﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SAC.sqlHelper;
using SAC.Helper;
using SAC.Power;
using SAC.Elink;
using System.Data;
using System.Collections;

namespace DAL
{
    /// <summary>
    /// 公用计算方法
    /// </summary>
    public class DALUtilityMehtod
    {
        string mon;
        string bm = "";
        string sql = "";
        string errMsg = "";
        string rtDBType = "";

        string pID1 = "fdj1zxyg";              //1号机组电量编号
        string pID2 = "fdj2zxyg";              //2号机组电量编号
        double dlA = 0;
        double dlB = 0;

        string tag = "";

        //凝补水率
        string tagNbs1 = "WHSIS.U1APSH.U1A03792";   //凝补水累计点名
        string tagZhq1 = "WHSIS.U1APSH.U1A03815";   //主蒸汽累计点名

        string tagNbs2 = "WHSIS.U2APSH.U2A03792";   //凝补水累计点名
        string tagZhq2 = "WHSIS.U2APSH.U2A03815";   //主蒸汽累计点名

        StrHelper sh = new StrHelper();

        /// <summary>
        /// 上网电量
        /// #1机组
        /// </summary>
        string xl1ID1 = "zb1zxyg"; //天瑞2836线主表正向有功 xl1zxyg 


        /// <summary>
        /// 上网电量
        /// #2机组 
        /// </summary>
        string xl2ID1 = "zb2zxyg";     //天瑞2836线主表正向有功 xl1zxyg 


        string qbb1zxyg1ID = "qbb1zxyg";    //启备变
        string qbb1zxyg2ID = "qbb1zxyg";

        string tlb1ID = "tlb1zxyg";         //脱硫变
        string tlb2ID = "";

        string gcb1ID = "gcbzxyg";          //高厂变
        string gcb2ID = "gcb2zxyg";

        string ggb1ID = "ggbzxyg";          //高公变
        string ggb2ID = "ggb2zxyg";

        string lcb1ID = "lcbzxyg";          //励磁变
        string lcb2ID = "lcb2zxyg";


        Elink ek = new Elink();
        PowerCale pc = new PowerCale();

        private string init()
        {
            rtDBType = IniHelper.ReadIniData("RelationDBbase", "DBType", null);

            return rtDBType;
        }

        /// <summary>
        /// 电量计算
        /// </summary>
        /// <param name="bt">开始时间</param>
        /// <param name="et">结束时间</param>
        /// <param name="unit">机组</param>       
        public string fdl(string qsrq, string jsrq, int unit)
        {
            string dl = "";

            if (unit == 0)
            {
                dlA = double.Parse(pc.GetPower(dlA, pID1, qsrq, jsrq, bm).ToString()) / 10000;
                dlB = double.Parse(pc.GetPower(dlB, pID2, qsrq, jsrq, bm).ToString()) / 10000;

                mon = "(" + dlA.ToString() + ")+(" + dlB.ToString() + ")";

                dl = StrHelper.Cale(mon);

            }
            else if (unit == 1)
            {
                dlA = double.Parse(pc.GetPower(dlA, pID1, qsrq, jsrq, bm).ToString()) / 10000;
                dl = dlA.ToString();
            }
            else
            {
                dlB = double.Parse(pc.GetPower(dlB, pID2, qsrq, jsrq, bm).ToString()) / 10000;
                dl = dlB.ToString();
            }

            return dl;
        }


        /// <summary>
        /// 上网电量
        /// </summary>
        /// <param name="repName"></param>
        /// <param name="repType"></param>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public string swdl(string repType, string qsrq, string jsrq, int unit)
        {
            double xl11 = 0;
            string res = "";

            if (repType == "值报")
            {
                if (unit == 1)
                {
                    xl11 = double.Parse(pc.GetPower(xl11, xl1ID1, qsrq, jsrq, bm).ToString()) / 10000;
                }
                else
                {
                    xl11 = double.Parse(pc.GetPower(xl11, xl2ID1, qsrq, jsrq, bm).ToString()) / 10000;
                }

                res = xl11.ToString();
            }
            else if (repType == "日报")
            {
                if (unit == 1)
                {
                    xl11 = double.Parse(pc.GetPower(xl11, xl1ID1, qsrq, jsrq, bm).ToString()) / 10000;
                }
                else
                {
                    xl11 = double.Parse(pc.GetPower(xl11, xl2ID1, qsrq, jsrq, bm).ToString()) / 10000;
                }

                res = xl11.ToString();
            }
            else if (repType == "月报")
            {
                if (unit == 1)
                {
                    xl11 = double.Parse(pc.GetPower(xl11, xl1ID1, qsrq, jsrq, bm).ToString()) / 10000;
                }
                else
                {
                    xl11 = double.Parse(pc.GetPower(xl11, xl2ID1, qsrq, jsrq, bm).ToString()) / 10000;
                }

                res = xl11.ToString();
            }
            else if (repType == "年报")
            {
                if (unit == 1)
                {
                    xl11 = double.Parse(pc.GetPower(xl11, xl1ID1, qsrq, jsrq, bm).ToString()) / 10000;
                }
                else
                {
                    xl11 = double.Parse(pc.GetPower(xl11, xl2ID1, qsrq, jsrq, bm).ToString()) / 10000;
                }
                res = xl11.ToString();
            }


            return res;
        }

        /// <summary>
        /// 启备变电量
        /// </summary>
        /// <param name="repType"></param>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public string qbb(string repType, string qsrq, string jsrq, int unit)
        {
            string res = "";
            string resA = "";
            string resB = "";
            string fdlA = "";
            string fdlB = "";
            double value = 0;

            dlA = double.Parse(pc.GetPower(dlA, pID1, qsrq, jsrq, bm).ToString()) / 10000;
            fdlA = dlA.ToString();

            dlB = double.Parse(pc.GetPower(dlB, pID2, qsrq, jsrq, bm).ToString()) / 10000;
            fdlB = dlB.ToString();

            if (repType == "值报")
            {
                #region
                double x1 = 0;
                double x2 = 0;

                x1 = double.Parse(pc.GetPower(x1, qbb1zxyg1ID, qsrq, jsrq, bm).ToString()) / 10000;
                resA = x1.ToString();

                x2 = double.Parse(pc.GetPower(x2, qbb1zxyg2ID, qsrq, jsrq, bm).ToString()) / 10000;
                resB = x2.ToString();

                if (dlA > 0 && dlB > 0)
                {
                    if (unit == 0)
                    { value = x1 + x2; }
                    else
                    { value = (x1 + x2) / 2; }

                    res = value.ToString();
                }
                else if (dlA > 0)
                {
                    if (unit == 0)
                    { res = resA; }
                    else if (unit == 1)
                    { res = "0"; }
                    else if (unit == 2)
                    { res = resA; }
                }
                else
                {
                    if (unit == 0)
                    { res = resB; }
                    else if (unit == 1)
                    { res = resB; }
                    if (unit == 2)
                    { res = "0"; }
                }
                #endregion
            }
            else if (repType == "日报")
            {
                #region
                double x1 = 0;
                double x2 = 0;

                x1 = double.Parse(pc.GetPower(x1, qbb1zxyg1ID, qsrq, jsrq, bm).ToString()) / 10000;
                resA = x1.ToString();

                x2 = double.Parse(pc.GetPower(x2, qbb1zxyg2ID, qsrq, jsrq, bm).ToString()) / 10000;
                resB = x2.ToString();

                if (dlA > 0 && dlB > 0)
                {
                    if (unit == 0)
                    { value = (x1 + x2) / 4; }
                    else
                    { value = (x1 + x2) / 2; }

                    res = value.ToString();
                }
                else if (dlA > 0)
                {
                    if (unit == 0)
                    { res = resA; }
                    else if (unit == 1)
                    { res = "0"; }
                    else if (unit == 2)
                    { res = resA; }
                }
                else
                {
                    if (unit == 0)
                    { res = resB; }
                    else if (unit == 1)
                    { res = resB; }
                    if (unit == 2)
                    { res = "0"; }
                }

                #endregion
            }
            else if (repType == "月报")
            {
                #region
                double x1 = 0;
                double x2 = 0;

                x1 = double.Parse(pc.GetPower(x1, qbb1zxyg1ID, qsrq, jsrq, bm).ToString()) / 10000;
                resA = x1.ToString();

                x2 = double.Parse(pc.GetPower(x2, qbb1zxyg2ID, qsrq, jsrq, bm).ToString()) / 10000;
                resB = x2.ToString();

                if (dlA > 0 && dlB > 0)
                {
                    if (unit == 0)
                    { value = x1 + x2; }
                    else
                    { value = (x1 + x2) / 2; }

                    res = value.ToString();
                }
                else if (dlA > 0)
                {
                    if (unit == 0)
                    { res = resA; }
                    else if (unit == 1)
                    { res = "0"; }
                    else if (unit == 2)
                    { res = resA; }
                }
                else
                {
                    if (unit == 0)
                    { res = resB; }
                    else if (unit == 1)
                    { res = resB; }
                    if (unit == 2)
                    { res = "0"; }
                }
                #endregion
            }
            else if (repType == "年报")
            {
                #region
                double x1 = 0;
                double x2 = 0;

                x1 = double.Parse(pc.GetPower(x1, qbb1zxyg1ID, qsrq, jsrq, bm).ToString()) / 10000;
                resA = x1.ToString();

                x2 = double.Parse(pc.GetPower(x2, qbb1zxyg2ID, qsrq, jsrq, bm).ToString()) / 10000;
                resB = x2.ToString();

                if (dlA > 0 && dlB > 0)
                {
                    if (unit == 0)
                    { value = x1 + x2; }
                    else
                    { value = (x1 + x2) / 2; }

                    res = value.ToString();
                }
                else if (dlA > 0)
                {
                    if (unit == 0)
                    { res = resA; }
                    else if (unit == 1)
                    { res = "0"; }
                    else if (unit == 2)
                    { res = resA; }
                }
                else
                {
                    if (unit == 0)
                    { res = resB; }
                    else if (unit == 1)
                    { res = resB; }
                    if (unit == 2)
                    { res = "0"; }
                }
                #endregion
            }

            return res.ToString();
        }

        /// <summary>
        /// 脱硫变电量
        /// </summary>
        /// <param name="repType"></param>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public string tlb(string repType, string qsrq, string jsrq, int unit)
        {
            string res = "";

            if (repType == "值报")
            {
                double x1 = 0;
                double x2 = 0;

                if (unit == 1)
                {
                    x1 = double.Parse(pc.GetPower(x1, tlb1ID, qsrq, jsrq, bm).ToString()) / 10000;
                    res = x1.ToString();
                }
                else
                {
                    x2 = double.Parse(pc.GetPower(x2, tlb2ID, qsrq, jsrq, bm).ToString()) / 10000;
                    res = x2.ToString();
                }
            }
            else if (repType == "日报")
            {
                double x1 = 0;
                double x2 = 0;

                if (unit == 1)
                {
                    x1 = double.Parse(pc.GetPower(x1, tlb1ID, qsrq, jsrq, bm).ToString()) / 10000;
                    res = x1.ToString();
                }
                else
                {
                    x2 = double.Parse(pc.GetPower(x2, tlb2ID, qsrq, jsrq, bm).ToString()) / 10000;
                    res = x2.ToString();
                }
            }
            else if (repType == "月报")
            {
                double x1 = 0;
                double x2 = 0;

                if (unit == 1)
                {
                    x1 = double.Parse(pc.GetPower(x1, tlb1ID, qsrq, jsrq, bm).ToString()) / 10000;
                    res = x1.ToString();
                }
                else if (unit == 2)
                {
                    x2 = double.Parse(pc.GetPower(x2, tlb2ID, qsrq, jsrq, bm).ToString()) / 10000;
                    res = x2.ToString();
                }
                else
                {
                    x1 = double.Parse(pc.GetPower(x1, tlb1ID, qsrq, jsrq, bm).ToString()) / 10000;
                    x2 = double.Parse(pc.GetPower(x2, tlb2ID, qsrq, jsrq, bm).ToString()) / 10000;
                    double value = x2 + x1;
                    res = value.ToString();
                }
            }
            else if (repType == "年报")
            {
                #region
                double x1 = 0;
                double x2 = 0;

                if (unit == 1)
                {
                    x1 = double.Parse(pc.GetPower(x1, tlb1ID, qsrq, jsrq, bm).ToString()) / 10000;
                    res = x1.ToString();
                }
                else if (unit == 2)
                {
                    x2 = double.Parse(pc.GetPower(x2, tlb2ID, qsrq, jsrq, bm).ToString()) / 10000;
                    res = x2.ToString();
                }
                else
                {
                    x1 = double.Parse(pc.GetPower(x1, tlb1ID, qsrq, jsrq, bm).ToString()) / 10000;
                    x2 = double.Parse(pc.GetPower(x2, tlb2ID, qsrq, jsrq, bm).ToString()) / 10000;
                    double value = x2 + x1;
                    res = value.ToString();
                }
                #endregion
            }


            return res.ToString();
        }

        /// <summary>
        /// 高厂变电量
        /// </summary>
        /// <param name="repType"></param>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public string gcb(string repType, string qsrq, string jsrq, int unit)
        {
            string res = "";

            if (repType == "值报")
            {
                double x1 = 0;
                double x2 = 0;

                if (unit == 1)
                {
                    x1 = double.Parse(pc.GetPower(x1, gcb1ID, qsrq, jsrq, bm).ToString()) / 10;
                    res = x1.ToString();
                }
                else
                {
                    x2 = double.Parse(pc.GetPower(x2, gcb2ID, qsrq, jsrq, bm).ToString()) / 10;
                    res = x2.ToString();
                }
            }
            else if (repType == "日报")
            {
                double x1 = 0;
                double x2 = 0;

                if (unit == 1)
                {
                    x1 = double.Parse(pc.GetPower(x1, gcb1ID, qsrq, jsrq, bm).ToString()) / 10;
                    res = x1.ToString();
                }
                else
                {
                    x2 = double.Parse(pc.GetPower(x2, gcb2ID, qsrq, jsrq, bm).ToString()) / 10;
                    res = x2.ToString();
                }
            }
            else if (repType == "月报")
            {
                double x1 = 0;
                double x2 = 0;

                if (unit == 1)
                {
                    x1 = double.Parse(pc.GetPower(x1, gcb1ID, qsrq, jsrq, bm).ToString()) / 10;
                    res = x1.ToString();
                }
                else
                {
                    x2 = double.Parse(pc.GetPower(x2, gcb2ID, qsrq, jsrq, bm).ToString()) / 10;
                    res = x2.ToString();
                }
            }
            else if (repType == "年报")
            {
                #region
                double x1 = 0;
                double x2 = 0;

                if (unit == 1)
                {
                    x1 = double.Parse(pc.GetPower(x1, gcb1ID, qsrq, jsrq, bm).ToString()) / 10;
                    res = x1.ToString();
                }
                else
                {
                    x2 = double.Parse(pc.GetPower(x2, gcb2ID, qsrq, jsrq, bm).ToString()) / 10;
                    res = x2.ToString();
                }
                #endregion
            }

            return res.ToString();
        }

        /// <summary>
        /// 高公变电量
        /// </summary>
        /// <param name="repType"></param>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public string ggb(string repType, string qsrq, string jsrq, int unit)
        {
            string res = "";

            if (repType == "值报")
            {
                double x1 = 0;
                double x2 = 0;

                if (unit == 1)
                {
                    x1 = double.Parse(pc.GetPower(x1, ggb1ID, qsrq, jsrq, bm).ToString()) / 10;
                    res = x1.ToString();
                }
                else
                {
                    x2 = double.Parse(pc.GetPower(x2, ggb2ID, qsrq, jsrq, bm).ToString()) / 10;
                    res = x2.ToString();
                }
            }
            else if (repType == "日报")
            {
                double x1 = 0;
                double x2 = 0;

                if (unit == 1)
                {
                    x1 = double.Parse(pc.GetPower(x1, ggb1ID, qsrq, jsrq, bm).ToString()) / 10;
                    res = x1.ToString();
                }
                else
                {
                    x2 = double.Parse(pc.GetPower(x2, ggb2ID, qsrq, jsrq, bm).ToString()) / 10;
                    res = x2.ToString();
                }
            }
            else if (repType == "月报")
            {
                double x1 = 0;
                double x2 = 0;

                if (unit == 1)
                {
                    x1 = double.Parse(pc.GetPower(x1, ggb1ID, qsrq, jsrq, bm).ToString()) / 10;
                    res = x1.ToString();
                }
                else
                {
                    x2 = double.Parse(pc.GetPower(x2, ggb2ID, qsrq, jsrq, bm).ToString()) / 10;
                    res = x2.ToString();
                }
            }
            else if (repType == "年报")
            {
                #region
                double x1 = 0;
                double x2 = 0;

                if (unit == 1)
                {
                    x1 = double.Parse(pc.GetPower(x1, ggb1ID, qsrq, jsrq, bm).ToString()) / 10;
                    res = x1.ToString();
                }
                else
                {
                    x2 = double.Parse(pc.GetPower(x2, ggb2ID, qsrq, jsrq, bm).ToString()) / 10;
                    res = x2.ToString();
                }
                #endregion
            }


            return res.ToString();
        }

        /// <summary>
        /// 励磁变电量
        /// </summary>
        /// <param name="repType"></param>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public string lcb(string repType, string qsrq, string jsrq, int unit)
        {
            string res = "";

            if (repType == "值报")
            {
                double x1 = 0;
                double x2 = 0;

                if (unit == 1)
                {
                    x1 = double.Parse(pc.GetPower(x1, lcb1ID, qsrq, jsrq, bm).ToString()) / 10000;
                    res = x1.ToString();
                }
                else
                {
                    x2 = double.Parse(pc.GetPower(x2, lcb2ID, qsrq, jsrq, bm).ToString()) / 10000;
                    res = x2.ToString();
                }
            }
            else if (repType == "日报")
            {
                double x1 = 0;
                double x2 = 0;

                if (unit == 1)
                {
                    x1 = double.Parse(pc.GetPower(x1, lcb1ID, qsrq, jsrq, bm).ToString()) / 10000;
                    res = x1.ToString();
                }
                else
                {
                    x2 = double.Parse(pc.GetPower(x2, lcb2ID, qsrq, jsrq, bm).ToString()) / 10000;
                    res = x2.ToString();
                }
            }
            else if (repType == "月报")
            {
                double x1 = 0;
                double x2 = 0;

                if (unit == 1)
                {
                    x1 = double.Parse(pc.GetPower(x1, lcb1ID, qsrq, jsrq, bm).ToString()) / 10000;
                    res = x1.ToString();
                }
                else
                {
                    x2 = double.Parse(pc.GetPower(x2, lcb2ID, qsrq, jsrq, bm).ToString()) / 10000;
                    res = x2.ToString();
                }
            }
            else if (repType == "年报")
            {
                double x1 = 0;
                double x2 = 0;
                #region
                if (unit == 1)
                {
                    x1 = double.Parse(pc.GetPower(x1, lcb1ID, qsrq, jsrq, bm).ToString()) / 10000;
                    res = x1.ToString();
                }
                else
                {
                    x2 = double.Parse(pc.GetPower(x2, lcb2ID, qsrq, jsrq, bm).ToString()) / 10000;
                    res = x2.ToString();
                }
                #endregion
            }

            return res.ToString();
        }

        /// <summary>
        /// 机组运行小时
        /// </summary>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public string jzyxxs(string qsrq, string jsrq, int unit)
        {
            object obj = "";

            string sql = " SELECT SUM(运行小时) AS Expr1 FROM 机组运行小时数据表 WHERE (设备类型='发电机') AND (机组 = " + unit + ") AND (日期 >= '" + qsrq + "') AND (日期 < '" + jsrq + "')";

            obj = DBsql.RunSingle(sql, out errMsg);

            if (obj != null && obj != "" && obj != " ")
            {
                return obj.ToString();
            }
            else
            {
                return "0";
            }
        }

        /// <summary>
        /// 统计小时
        /// </summary>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public string tjxs(string qsrq, string jsrq, int unit)
        {
            object obj = null;

            this.init();

            if (rtDBType == "SQL")
            {
                sql = " SELECT sum(运行小时) FROM 参数运行小时统计表 where 统计参数='统计时间' and 机组=" + unit + " and 时间>='" + qsrq + "' and 时间<'" + jsrq + "'";
                obj = DBsql.RunSingle(sql, out errMsg);
            }
            else if (rtDBType == "DB2")
            {
                sql = " SELECT sum(运行小时) FROM 参数运行小时统计表 where 统计参数='统计时间' and 机组=" + unit + " and 时间>='" + qsrq + "' and 时间<'" + jsrq + "'";
            }

            if (obj != null && obj != "" && obj != " ")
            {
                if (obj.ToString() != "")
                    return obj.ToString();
                else
                    return "0";
            }
            else
            {
                return "0";
            }
        }

        /// <summary>
        /// 凝补水率
        /// </summary>
        /// <param name="tagNbs"></param>
        /// <param name="tagZhq"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public string nbsl(string qsrq, string jsrq, int unit)
        {
            double nbsDiff = 0;
            double zhqDiff = 0;
            string val = "0";

            int ret = -1;

            if (unit == 2)
            {
                ek.GetHisDiffValue(tagNbs2, qsrq, jsrq, ref ret, ref nbsDiff);
                ek.GetHisDiffValue(tagZhq2, qsrq, jsrq, ref ret, ref zhqDiff);

                try
                {
                    mon = nbsDiff.ToString() + "/" + zhqDiff.ToString() + "*100";
                    val = StrHelper.Cale(mon);
                }
                catch { val = "0"; }

                val = StrHelper.checkCatch(val);
            }
            else if (unit == 1)
            {
                ek.GetHisDiffValue(tagNbs1, qsrq, jsrq, ref ret, ref nbsDiff);
                ek.GetHisDiffValue(tagZhq1, qsrq, jsrq, ref ret, ref zhqDiff);

                try
                {
                    mon = nbsDiff.ToString() + "/" + zhqDiff.ToString() + "*100";
                    val = StrHelper.Cale(mon);
                }
                catch { val = "0"; }

                val = StrHelper.checkCatch(val);
            }
            else
            {
                double nbsDiff1 = 0;
                double zhqDiff1 = 0;

                ek.GetHisDiffValue(tagNbs1, qsrq, jsrq, ref ret, ref nbsDiff1);
                ek.GetHisDiffValue(tagZhq1, qsrq, jsrq, ref ret, ref zhqDiff1);

                ek.GetHisDiffValue(tagNbs2, qsrq, jsrq, ref ret, ref nbsDiff);
                ek.GetHisDiffValue(tagZhq2, qsrq, jsrq, ref ret, ref zhqDiff);

                try
                {
                    mon = "((" + nbsDiff.ToString() + ")+(" + nbsDiff1.ToString() + "))/((" + zhqDiff1.ToString() + ")+(" + zhqDiff.ToString() + "))*100";
                    val = StrHelper.Cale(mon);
                }
                catch { val = "0"; }

                val = StrHelper.checkCatch(val);
            }

            return val;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="repName"></param>
        /// <param name="repType"></param>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public string nbsl(string repName, string repType, string qsrq, string jsrq, int unit)
        {
            double nbsDiff = 0;
            double zhqDiff = 0;
            string val = "0";
            object obj;
            string sql = "";
            string res = "";
            int ret = -1;

            if (repType == "日报")
            {
                #region
                if (unit != 0)
                {
                    sql = "SELECT 数值 FROM 锅炉蒸发量数据表 where 时间='" + Convert.ToDateTime(qsrq).ToShortDateString() + "' and 机组='" + unit + "'";

                    obj = DBsql.RunSingle(sql, out errMsg);

                    if (obj != null)
                    {
                        zhqDiff = double.Parse(obj.ToString());
                    }
                    else
                    {
                        string tag = "";

                        if (unit == 1)
                            tag = tagZhq1;
                        else
                            tag = tagZhq2;

                        ek.GetHisDiffValue(tag, qsrq, jsrq, ref ret, ref zhqDiff);
                    }

                    string tagName = "";

                    if (unit == 1)
                        tagName = tagNbs1;
                    else
                        tagName = tagNbs2;

                    ek.GetHisDiffValue(tagName, qsrq, jsrq, ref ret, ref nbsDiff);

                    try
                    {
                        mon = nbsDiff.ToString() + "/" + zhqDiff.ToString() + "*100";
                        val = StrHelper.Cale(mon);
                    }
                    catch { val = "0"; }

                    val = StrHelper.checkCatch(val);
                }
                else
                {

                    sql = "SELECT 数值 FROM 锅炉蒸发量数据表 where 时间='" + Convert.ToDateTime(qsrq).ToShortDateString() + "' and 机组=1";

                    obj = DBsql.RunSingle(sql, out errMsg);

                    if (obj != null)
                    {
                        zhqDiff = double.Parse(obj.ToString());
                    }
                    else
                    {
                        string tag = "";

                        tag = tagZhq1;

                        //string eDate = DateTime.Parse(qsrq).AddDays(+1).ToString("yyyy-MM-dd H:mm:ss");

                        ek.GetHisDiffValue(tag, qsrq, jsrq, ref ret, ref zhqDiff);
                    }

                    double zhqDiffA = zhqDiff;

                    sql = "SELECT 数值 FROM 锅炉蒸发量数据表 where 时间='" + Convert.ToDateTime(qsrq).ToShortDateString() + "' and 机组=2";

                    obj = DBsql.RunSingle(sql, out errMsg);

                    if (obj != null)
                    {
                        zhqDiff = double.Parse(obj.ToString());
                    }
                    else
                    {
                        string tag = "";

                        tag = tagZhq2;

                        //string eDate = DateTime.Parse(qsrq).AddDays(+1).ToString("yyyy-MM-dd H:mm:ss");

                        ek.GetHisDiffValue(tag, qsrq, jsrq, ref ret, ref zhqDiff);
                    }

                    double zhqDiffB = zhqDiff;

                    double nbsDiffA = 0;
                    double nbsDiffB = 0;

                    ek.GetHisDiffValue(tagNbs1, qsrq, jsrq, ref ret, ref nbsDiffA);

                    ek.GetHisDiffValue(tagNbs2, qsrq, jsrq, ref ret, ref nbsDiffB);

                    try
                    {
                        mon = "((" + nbsDiffA.ToString() + ")+(" + nbsDiffB.ToString() + "))" + "/((" + zhqDiffA.ToString() + ")+(" + zhqDiffB.ToString() + "))*100";
                        val = StrHelper.Cale(mon);
                    }
                    catch { val = "0"; }

                    val = StrHelper.checkCatch(val);
                }
                #endregion
            }
            else if (repType == "月报")
            {
                #region
                if (unit != 0)
                {
                    string[] date = sh.DateDiff(DateTime.Parse(qsrq), DateTime.Parse(jsrq));

                    for (int i = 0; i < date.Length - 1; i++)
                    {
                        sql = "SELECT 数值 FROM 锅炉蒸发量数据表 where 时间='" + Convert.ToDateTime(date[i]).ToShortDateString() + "' and 机组='" + unit + "'";

                        obj = DBsql.RunSingle(sql, out errMsg);

                        if (obj != null)
                        {
                            zhqDiff = double.Parse(obj.ToString());
                        }
                        else
                        {
                            string tag = "";

                            if (unit == 1)
                                tag = tagZhq1;
                            else
                                tag = tagZhq2;

                            string eDate = DateTime.Parse(qsrq).AddDays(+1).ToString("yyyy-MM-dd H:mm:ss");

                            ek.GetHisDiffValue(tag, qsrq, eDate, ref ret, ref zhqDiff);
                        }

                        mon += "(" + zhqDiff + ")+";
                    }

                    mon = mon.TrimEnd('+');
                    try
                    { res = StrHelper.Cale(mon); }
                    catch { res = "0"; }

                    res = StrHelper.checkCatch(res);
                    zhqDiff = double.Parse(res);

                    string tagName = "";

                    if (unit == 1)
                        tagName = tagNbs1;
                    else
                        tagName = tagNbs2;

                    ek.GetHisDiffValue(tagName, qsrq, jsrq, ref ret, ref nbsDiff);

                    try
                    {
                        mon = nbsDiff.ToString() + "/" + zhqDiff.ToString() + "*100";
                        val = StrHelper.Cale(mon);
                    }
                    catch { val = "0"; }

                    val = StrHelper.checkCatch(val);
                }
                else
                {
                    string[] date = sh.DateDiff(DateTime.Parse(qsrq), DateTime.Parse(jsrq));

                    for (int i = 0; i < date.Length - 1; i++)
                    {
                        sql = "SELECT 数值 FROM 锅炉蒸发量数据表 where 时间='" + Convert.ToDateTime(date[i]).ToShortDateString() + "' and 机组=1";

                        obj = DBsql.RunSingle(sql, out errMsg);

                        if (obj != null)
                        {
                            zhqDiff = double.Parse(obj.ToString());
                        }
                        else
                        {
                            string tag = "";

                            tag = tagZhq1;

                            string eDate = DateTime.Parse(qsrq).AddDays(+1).ToString("yyyy-MM-dd H:mm:ss");

                            ek.GetHisDiffValue(tag, qsrq, eDate, ref ret, ref zhqDiff);
                        }

                        mon += "(" + zhqDiff + ")+";
                    }

                    mon = mon.TrimEnd('+');
                    try
                    { res = StrHelper.Cale(mon); }
                    catch { res = "0"; }

                    res = StrHelper.checkCatch(res);
                    double zhqDiffA = double.Parse(res);

                    for (int i = 0; i < date.Length - 1; i++)
                    {
                        sql = "SELECT 数值 FROM 锅炉蒸发量数据表 where 时间='" + Convert.ToDateTime(date[i]).ToShortDateString() + "' and 机组=2";

                        obj = DBsql.RunSingle(sql, out errMsg);

                        if (obj != null)
                        {
                            zhqDiff = double.Parse(obj.ToString());
                        }
                        else
                        {
                            string tag = "";

                            tag = tagZhq2;

                            string eDate = DateTime.Parse(qsrq).AddDays(+1).ToString("yyyy-MM-dd H:mm:ss");

                            ek.GetHisDiffValue(tag, qsrq, eDate, ref ret, ref zhqDiff);
                        }

                        mon += "(" + zhqDiff + ")+";
                    }

                    mon = mon.TrimEnd('+');
                    try
                    { res = StrHelper.Cale(mon); }
                    catch { res = "0"; }

                    res = StrHelper.checkCatch(res);
                    double zhqDiffB = double.Parse(res);

                    double nbsDiffA = 0;
                    double nbsDiffB = 0;

                    ek.GetHisDiffValue(tagNbs1, qsrq, jsrq, ref ret, ref nbsDiffA);

                    ek.GetHisDiffValue(tagNbs2, qsrq, jsrq, ref ret, ref nbsDiffB);

                    try
                    {
                        mon = "((" + nbsDiffA.ToString() + ")+(" + nbsDiffB.ToString() + "))" + "/((" + zhqDiffA.ToString() + ")+(" + zhqDiffB.ToString() + "))*100";
                        val = StrHelper.Cale(mon);
                    }
                    catch { val = "0"; }

                    val = StrHelper.checkCatch(val);
                }
                #endregion
            }
            else if (repType == "年报")
            {
                #region
                if (unit != 0)
                {
                    string[] date = sh.DateDiff(DateTime.Parse(qsrq), DateTime.Parse(jsrq));

                    for (int i = 0; i < date.Length - 1; i++)
                    {
                        sql = "SELECT 数值 FROM 锅炉蒸发量数据表 where 时间='" + Convert.ToDateTime(date[i]).ToShortDateString() + "' and 机组='" + unit + "'";

                        obj = DBsql.RunSingle(sql, out errMsg);

                        if (obj != null)
                        {
                            zhqDiff = double.Parse(obj.ToString());
                        }
                        else
                        {
                            string tag = "";

                            if (unit == 1)
                                tag = tagZhq1;
                            else
                                tag = tagZhq2;

                            string eDate = DateTime.Parse(qsrq).AddDays(+1).ToString("yyyy-MM-dd H:mm:ss");

                            ek.GetHisDiffValue(tag, qsrq, eDate, ref ret, ref zhqDiff);
                        }

                        mon += "(" + zhqDiff + ")+";
                    }

                    mon = mon.TrimEnd('+');
                    try
                    { res = StrHelper.Cale(mon); }
                    catch { res = "0"; }

                    res = StrHelper.checkCatch(res);
                    zhqDiff = double.Parse(res);

                    string tagName = "";

                    if (unit == 1)
                        tagName = tagNbs1;
                    else
                        tagName = tagNbs2;

                    ek.GetHisDiffValue(tagName, qsrq, jsrq, ref ret, ref nbsDiff);

                    try
                    {
                        mon = nbsDiff.ToString() + "/" + zhqDiff.ToString() + "*100";
                        val = StrHelper.Cale(mon);
                    }
                    catch { val = "0"; }

                    val = StrHelper.checkCatch(val);
                }
                else
                {
                    string[] date = sh.DateDiff(DateTime.Parse(qsrq), DateTime.Parse(jsrq));

                    for (int i = 0; i < date.Length - 1; i++)
                    {
                        sql = "SELECT 数值 FROM 锅炉蒸发量数据表 where 时间='" + Convert.ToDateTime(date[i]).ToShortDateString() + "' and 机组=1";

                        obj = DBsql.RunSingle(sql, out errMsg);

                        if (obj != null)
                        {
                            zhqDiff = double.Parse(obj.ToString());
                        }
                        else
                        {
                            string tag = "";

                            tag = tagZhq1;

                            string eDate = DateTime.Parse(qsrq).AddDays(+1).ToString("yyyy-MM-dd H:mm:ss");

                            ek.GetHisDiffValue(tag, qsrq, eDate, ref ret, ref zhqDiff);
                        }

                        mon += "(" + zhqDiff + ")+";
                    }

                    mon = mon.TrimEnd('+');
                    try
                    { res = StrHelper.Cale(mon); }
                    catch { res = "0"; }

                    res = StrHelper.checkCatch(res);
                    double zhqDiffA = double.Parse(res);

                    for (int i = 0; i < date.Length - 1; i++)
                    {
                        sql = "SELECT 数值 FROM 锅炉蒸发量数据表 where 时间='" + Convert.ToDateTime(date[i]).ToShortDateString() + "' and 机组=2";

                        obj = DBsql.RunSingle(sql, out errMsg);

                        if (obj != null)
                        {
                            zhqDiff = double.Parse(obj.ToString());
                        }
                        else
                        {
                            string tag = "";

                            tag = tagZhq2;

                            string eDate = DateTime.Parse(qsrq).AddDays(+1).ToString("yyyy-MM-dd H:mm:ss");

                            ek.GetHisDiffValue(tag, qsrq, eDate, ref ret, ref zhqDiff);
                        }

                        mon += "(" + zhqDiff + ")+";
                    }

                    mon = mon.TrimEnd('+');
                    try
                    { res = StrHelper.Cale(mon); }
                    catch { res = "0"; }

                    res = StrHelper.checkCatch(res);
                    double zhqDiffB = double.Parse(res);

                    double nbsDiffA = 0;
                    double nbsDiffB = 0;

                    ek.GetHisDiffValue(tagNbs1, qsrq, jsrq, ref ret, ref nbsDiffA);

                    ek.GetHisDiffValue(tagNbs2, qsrq, jsrq, ref ret, ref nbsDiffB);

                    try
                    {
                        mon = "((" + nbsDiffA.ToString() + ")+(" + nbsDiffB.ToString() + "))" + "/((" + zhqDiffA.ToString() + ")+(" + zhqDiffB.ToString() + "))*100";
                        val = StrHelper.Cale(mon);
                    }
                    catch { val = "0"; }

                    val = StrHelper.checkCatch(val);
                }
                #endregion
            }

            return val;
        }

        /// <summary>
        /// 高加运行时间
        /// </summary>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public string gjyxxs(string qsrq, string jsrq, int unit)
        {
            object obj = "";
            string sql = " SELECT SUM(运行小时) AS Expr1 FROM 机组运行小时数据表 WHERE (设备类型='高压加热器') AND (机组 = " + unit + ") AND (日期 >= '" + qsrq + "') AND (日期 < '" + jsrq + "')";

            obj = DBsql.RunSingle(sql, out errMsg);

            if (obj != null)
            {
                return obj.ToString();
            }
            else
            {
                return "0";
            }
        }

        /// <summary>
        /// 循环水温升
        /// </summary>
        /// <param name="repName">报表名称</param>
        /// <param name="jsrq">结束时间</param>
        /// <param name="unit">机组</param>
        /// <returns></returns>
        public string xhsws(string repName, string jsrq, int unit)
        {
            int ret = -1;
            string sql = "";

            double xhsc = 0;
            double xhsj = 0;
            double value = 0;

            sql = "SELECT 小时点 FROM T_Sheet_SheetPara WHERE (报表名称 = '" + repName + "') AND (机组 = '" + unit + "') AND (参数名 = '循环水出水温度')";

            tag = DBsql.RunSingle(sql, out errMsg).ToString();

            ek.GetHisValue(tag, jsrq, ref ret, ref xhsc);


            sql = "SELECT 小时点 FROM T_Sheet_SheetPara WHERE (报表名称 = '" + repName + "') AND (机组 = '" + unit + "') AND (参数名 = '循环水进水温度')";

            tag = DBsql.RunSingle(sql, out errMsg).ToString();

            ek.GetHisValue(tag, jsrq, ref ret, ref xhsj);

            value = xhsc - xhsj;

            return value.ToString();
        }

        /// <summary>
        /// 循环水温升
        /// </summary>
        /// <param name="repName">报表名称</param>
        /// <param name="jsrq">结束时间</param>
        /// <param name="unit">机组</param>
        /// <returns></returns>
        public string xhsws(string repName, string repType, string jsrq, int unit)
        {
            int ret = -1;
            string sql = "";

            double xhsc = 0;
            double xhsj = 0;
            double value = 0;

            if (repType == "日报")
            {
                sql = "SELECT 日点 FROM T_Sheet_SheetPara WHERE (报表名称 = '" + repName + "') AND (机组 = '" + unit + "') AND (参数名 = '循环水出水温度')";

                tag = DBsql.RunSingle(sql, out errMsg).ToString();

                ek.GetHisValue(tag, jsrq, ref ret, ref xhsc);


                sql = "SELECT 日点 FROM T_Sheet_SheetPara WHERE (报表名称 = '" + repName + "') AND (机组 = '" + unit + "') AND (参数名 = '循环水进水温度')";

                tag = DBsql.RunSingle(sql, out errMsg).ToString();

                ek.GetHisValue(tag, jsrq, ref ret, ref xhsj);
            }
            else if (repType == "月报")
            {
                sql = "SELECT 月点 FROM T_Sheet_SheetPara WHERE (报表名称 = '" + repName + "') AND (机组 = '" + unit + "') AND (参数名 = '循环水出水温度')";

                tag = DBsql.RunSingle(sql, out errMsg).ToString();

                ek.GetHisValue(tag, jsrq, ref ret, ref xhsc);


                sql = "SELECT 月点 FROM T_Sheet_SheetPara WHERE (报表名称 = '" + repName + "') AND (机组 = '" + unit + "') AND (参数名 = '循环水进水温度')";

                tag = DBsql.RunSingle(sql, out errMsg).ToString();

                ek.GetHisValue(tag, jsrq, ref ret, ref xhsj);
            }
            else if (repType == "年报")
            {
                #region
                sql = "SELECT 年点 FROM T_Sheet_SheetPara WHERE (报表名称 = '" + repName + "') AND (机组 = '" + unit + "') AND (参数名 = '循环水出水温度')";

                tag = DBsql.RunSingle(sql, out errMsg).ToString();

                ek.GetHisValue(tag, jsrq, ref ret, ref xhsc);


                sql = "SELECT 年点 FROM T_Sheet_SheetPara WHERE (报表名称 = '" + repName + "') AND (机组 = '" + unit + "') AND (参数名 = '循环水进水温度')";

                tag = DBsql.RunSingle(sql, out errMsg).ToString();

                ek.GetHisValue(tag, jsrq, ref ret, ref xhsj);
                #endregion
            }
            value = xhsc - xhsj;

            return value.ToString();
        }

        /// <summary>
        /// 凝结器端差
        /// </summary>
        /// <param name="repName"></param>
        /// <param name="jsrq"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public string njqdc(string repName, string jsrq, int unit)
        {
            int ret = -1;
            string sql = "";

            double pqwd = 0;
            double xhsj = 0;
            double value = 0;

            sql = "SELECT 小时点 FROM T_Sheet_SheetPara WHERE (机组 = '" + unit + "') AND (参数名 = '排汽温度')";//(报表名称 = '" + repName + "') AND 

            tag = DBsql.RunSingle(sql, out errMsg).ToString();

            ek.GetHisValue(tag, jsrq, ref ret, ref pqwd);

            sql = "SELECT 小时点 FROM T_Sheet_SheetPara WHERE (报表名称 = '" + repName + "') AND (机组 = '" + unit + "') AND (参数名 = '循环水出水温度')";

            tag = DBsql.RunSingle(sql, out errMsg).ToString();

            ek.GetHisValue(tag, jsrq, ref ret, ref xhsj);

            value = pqwd - xhsj;

            return value.ToString();
        }

        public string njqdc(string repName, string repType, string jsrq, int unit)
        {
            int ret = -1;
            string sql = "";

            double pqwd = 0;
            double xhsj = 0;
            double value = 0;

            if (repType == "日报")
            {
                sql = "SELECT 日点 FROM T_Sheet_SheetPara WHERE (机组 = '" + unit + "') AND (参数名 = '排汽温度')";//(报表名称 = '" + repName + "') AND 

                tag = DBsql.RunSingle(sql, out errMsg).ToString();

                ek.GetHisValue(tag, jsrq, ref ret, ref pqwd);

                sql = "SELECT 日点 FROM T_Sheet_SheetPara WHERE (报表名称 = '" + repName + "') AND (机组 = '" + unit + "') AND (参数名 = '循环水出水温度')";

                tag = DBsql.RunSingle(sql, out errMsg).ToString();

                ek.GetHisValue(tag, jsrq, ref ret, ref xhsj);
            }
            else if (repType == "月报")
            {
                sql = "SELECT 月点 FROM T_Sheet_SheetPara WHERE (机组 = '" + unit + "') AND (参数名 = '排汽温度')";//(报表名称 = '" + repName + "') AND 

                tag = DBsql.RunSingle(sql, out errMsg).ToString();

                ek.GetHisValue(tag, jsrq, ref ret, ref pqwd);

                sql = "SELECT 月点 FROM T_Sheet_SheetPara WHERE (报表名称 = '" + repName + "') AND (机组 = '" + unit + "') AND (参数名 = '循环水出水温度')";

                tag = DBsql.RunSingle(sql, out errMsg).ToString();

                ek.GetHisValue(tag, jsrq, ref ret, ref xhsj);
            }
            else if (repType == "年报")
            {
                sql = "SELECT 年点 FROM T_Sheet_SheetPara WHERE (机组 = '" + unit + "') AND (参数名 = '排汽温度')";//(报表名称 = '" + repName + "') AND 

                tag = DBsql.RunSingle(sql, out errMsg).ToString();

                ek.GetHisValue(tag, jsrq, ref ret, ref pqwd);

                sql = "SELECT 年点 FROM T_Sheet_SheetPara WHERE (报表名称 = '" + repName + "') AND (机组 = '" + unit + "') AND (参数名 = '循环水出水温度')";

                tag = DBsql.RunSingle(sql, out errMsg).ToString();

                ek.GetHisValue(tag, jsrq, ref ret, ref xhsj);
            }

            value = pqwd - xhsj;

            return value.ToString();
        }

        /// <summary>
        /// 凝结水过冷度
        /// </summary>
        /// <param name="repName"></param>
        /// <param name="jsrq"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public string njsgld(string repName, string jsrq, int unit)
        {
            int ret = -1;
            string sql = "";

            double pqwd = 0;
            double njswd = 0;
            double value = 0;

            sql = "SELECT 小时点 FROM T_Sheet_SheetPara WHERE  (机组 = '" + unit + "') AND (参数名 = '排汽温度')";//(报表名称 = '" + repName + "') AND

            tag = DBsql.RunSingle(sql, out errMsg).ToString();

            ek.GetHisValue(tag, jsrq, ref ret, ref pqwd);

            sql = "SELECT 小时点 FROM T_Sheet_SheetPara WHERE (报表名称 = '" + repName + "') AND (机组 = '" + unit + "') AND (参数名 = '凝结水温度')";

            tag = DBsql.RunSingle(sql, out errMsg).ToString();

            ek.GetHisValue(tag, jsrq, ref ret, ref njswd);

            value = pqwd - njswd;

            return value.ToString();
        }

        public string njsgld(string repName, string repType, string jsrq, int unit)
        {
            int ret = -1;
            string sql = "";

            double pqwd = 0;
            double njswd = 0;
            double value = 0;
            if (repType == "日报")
            {
                sql = "SELECT 日点 FROM T_Sheet_SheetPara WHERE  (机组 = '" + unit + "') AND (参数名 = '排汽温度')";//(报表名称 = '" + repName + "') AND

                tag = DBsql.RunSingle(sql, out errMsg).ToString();

                ek.GetHisValue(tag, jsrq, ref ret, ref pqwd);

                sql = "SELECT 日点 FROM T_Sheet_SheetPara WHERE (报表名称 = '" + repName + "') AND (机组 = '" + unit + "') AND (参数名 = '凝结水温度')";

                tag = DBsql.RunSingle(sql, out errMsg).ToString();

                ek.GetHisValue(tag, jsrq, ref ret, ref njswd);
            }
            else if (repType == "月报")
            {
                sql = "SELECT 月点 FROM T_Sheet_SheetPara WHERE  (机组 = '" + unit + "') AND (参数名 = '排汽温度')";//(报表名称 = '" + repName + "') AND

                tag = DBsql.RunSingle(sql, out errMsg).ToString();

                ek.GetHisValue(tag, jsrq, ref ret, ref pqwd);

                sql = "SELECT 月点 FROM T_Sheet_SheetPara WHERE (报表名称 = '" + repName + "') AND (机组 = '" + unit + "') AND (参数名 = '凝结水温度')";

                tag = DBsql.RunSingle(sql, out errMsg).ToString();

                ek.GetHisValue(tag, jsrq, ref ret, ref njswd);
            }
            else if (repType == "年报")
            {
                sql = "SELECT 年点 FROM T_Sheet_SheetPara WHERE  (机组 = '" + unit + "') AND (参数名 = '排汽温度')";//(报表名称 = '" + repName + "') AND

                tag = DBsql.RunSingle(sql, out errMsg).ToString();

                ek.GetHisValue(tag, jsrq, ref ret, ref pqwd);

                sql = "SELECT 年点 FROM T_Sheet_SheetPara WHERE (报表名称 = '" + repName + "') AND (机组 = '" + unit + "') AND (参数名 = '凝结水温度')";

                tag = DBsql.RunSingle(sql, out errMsg).ToString();

                ek.GetHisValue(tag, jsrq, ref ret, ref njswd);
            }
            value = pqwd - njswd;

            return value.ToString();
        }

        /// <summary>
        /// 给水温度差 [差#2机组点]
        /// </summary>
        /// <param name="jsrq"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public string gswdDiff(string jsrq, int unit)
        {
            int ret = -1;
            double gjcswd = 0;
            double gswd = 0;
            double value = 0;

            if (unit == 1)
            {
                tag = "WHSIS.CALC.ZBTJD035";

                ek.GetHisValue(tag, jsrq, ref ret, ref gjcswd);

                tag = "WHSIS.CALC.ZBTJD007";

                ek.GetHisValue(tag, jsrq, ref ret, ref gswd);

                value = gjcswd - gswd;
            }
            else if (unit == 2)
            {
                tag = "";// "WHSIS.CALC.ZBTJD035";

                ek.GetHisValue(tag, jsrq, ref ret, ref gjcswd);

                tag = "";// "WHSIS.CALC.ZBTJD007";

                ek.GetHisValue(tag, jsrq, ref ret, ref gswd);

                value = gjcswd - gswd;
            }
            else
            {

                tag = "WHSIS.CALC.ZBTJD035";

                ek.GetHisValue(tag, jsrq, ref ret, ref gjcswd);

                tag = "WHSIS.CALC.ZBTJD007";

                ek.GetHisValue(tag, jsrq, ref ret, ref gswd);

                double value1 = gjcswd - gswd;

                tag = "";// "WHSIS.CALC.ZBTJD035";

                ek.GetHisValue(tag, jsrq, ref ret, ref gjcswd);

                tag = "";// "WHSIS.CALC.ZBTJD007";

                ek.GetHisValue(tag, jsrq, ref ret, ref gswd);

                double value2 = gjcswd - gswd;

                value = value1 + value2;
            }

            return value.ToString();
        }

        /// <summary>
        /// 主蒸汽流量累计
        /// </summary>
        /// <param name="repName">报表名称</param>
        /// <param name="repType">报表类型</param>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <param name="unit">0全厂</param>
        /// <returns></returns>
        public string MainStreamFlow(string repName, string repType, string qsrq, string jsrq, int unit)
        {
            int ret = -1;
            object obj;
            string sql = "";
            double zhqDiff = 0;
            string res = "";
            mon = "";
            if (repType == "值报")
            {
                sql = "SELECT 数值 FROM 锅炉蒸发量数据表 where 时间='" + Convert.ToDateTime(qsrq).ToShortDateString() + "' and 机组='" + unit + "'";

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                {
                    zhqDiff = double.Parse(obj.ToString()) / 3;
                }
                else
                {
                    string tag = "";

                    if (unit == 1)
                        tag = tagZhq1;
                    else
                        tag = tagZhq2;

                    ek.GetHisDiffValue(tag, qsrq, jsrq, ref ret, ref zhqDiff);

                    zhqDiff = zhqDiff / 3;
                }
            }
            else if (repType == "日报")
            {
                sql = "SELECT 数值 FROM 锅炉蒸发量数据表 where 时间='" + Convert.ToDateTime(qsrq).ToShortDateString() + "' and 机组='" + unit + "'";

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                {
                    zhqDiff = double.Parse(obj.ToString());
                }
                else
                {
                    string tag = "";

                    if (unit == 1)
                        tag = tagZhq1;
                    else
                        tag = tagZhq2;

                    ek.GetHisDiffValue(tag, qsrq, jsrq, ref ret, ref zhqDiff);
                }
            }
            else if (repType == "月报")
            {
                #region
                string[] date = sh.DateDiff(DateTime.Parse(qsrq), DateTime.Parse(jsrq));

                if (date == null)
                {
                    sql = "SELECT 数值 FROM 锅炉蒸发量数据表 where 时间='" + Convert.ToDateTime(qsrq).ToShortDateString() + "' and 机组='" + unit + "'";

                    obj = DBsql.RunSingle(sql, out errMsg);

                    if (obj != null)
                    {
                        zhqDiff = double.Parse(obj.ToString());
                    }
                    else
                    {
                        string tag = "";

                        if (unit == 1)
                            tag = tagZhq1;
                        else
                            tag = tagZhq2;

                        ek.GetHisDiffValue(tag, qsrq, jsrq, ref ret, ref zhqDiff);
                    }
                }
                else
                {
                    for (int i = 0; i < date.Length - 1; i++)
                    {
                        sql = "SELECT 数值 FROM 锅炉蒸发量数据表 where 时间='" + Convert.ToDateTime(date[i]).ToShortDateString() + "' and 机组='" + unit + "'";

                        obj = DBsql.RunSingle(sql, out errMsg);

                        if (obj != null)
                        {
                            zhqDiff = double.Parse(obj.ToString());
                        }
                        else
                        {
                            string tag = "";

                            if (unit == 1)
                                tag = tagZhq1;
                            else
                                tag = tagZhq2;

                            string eDate = DateTime.Parse(date[i]).AddDays(+1).AddSeconds(-1).ToString("yyyy-MM-dd H:mm:ss");

                            ek.GetHisDiffValue(tag, DateTime.Parse(date[i]).ToString("yyyy-MM-dd H:mm:ss"), eDate, ref ret, ref zhqDiff);
                        }

                        mon += "(" + zhqDiff + ")+";
                    }
                }
                mon = mon.TrimEnd('+');
                try
                { res = StrHelper.Cale(mon); }
                catch { res = "0"; }

                res = StrHelper.checkCatch(res);
                zhqDiff = double.Parse(res);
                #endregion
            }
            else if (repType == "年报")
            {
                #region
                string[] date = sh.DateDiff(DateTime.Parse(qsrq), DateTime.Parse(jsrq));

                for (int i = 0; i < date.Length - 1; i++)
                {
                    sql = "SELECT 数值 FROM 锅炉蒸发量数据表 where 时间='" + Convert.ToDateTime(date[i]).ToShortDateString() + "' and 机组='" + unit + "'";

                    obj = DBsql.RunSingle(sql, out errMsg);

                    if (obj != null)
                    {
                        zhqDiff = double.Parse(obj.ToString());
                    }
                    else
                    {
                        string tag = "";

                        if (unit == 1)
                            tag = tagZhq1;
                        else
                            tag = tagZhq2;

                        string eDate = DateTime.Parse(date[i]).AddDays(+1).AddSeconds(-1).ToString("yyyy-MM-dd H:mm:ss");

                        ek.GetHisDiffValue(tag, date[i], eDate, ref ret, ref zhqDiff);
                    }

                    mon += "(" + zhqDiff + ")+";
                }

                mon = mon.TrimEnd('+');
                try
                { res = StrHelper.Cale(mon); }
                catch { res = "0"; }

                res = StrHelper.checkCatch(res);
                zhqDiff = double.Parse(res);
                #endregion
            }

            return zhqDiff.ToString();
        }

        ///
        /// 锅炉值报指标
        ///

        //发电量

        //机组运行小时

        //锅炉蒸发量累计=主蒸汽流量累计

        /// <summary>
        /// 入炉煤低位热值
        /// </summary>
        /// <param name="repType"></param>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public string rlmdwfrl(string repType, string qsrq, string jsrq, int unit)
        {
            object objML1;
            object objML2;
            string val1 = "";
            string val2 = "";
            double res = 0;
            string mon = "";
            string re = "";

            string dwfrl1 = "0";
            string dwfrl2 = "0";
            string dwfrl3 = "0";

            string mz1ml1 = "0";     //煤量1
            string mz1ml2 = "0";
            string mz1ml3 = "0";

            string mz2ml1 = "0";     //煤量2
            string mz2ml2 = "0";
            string mz2ml3 = "0";

            string val = "";

            if (repType == "值报")
            {
                string sql = "select * from 入炉煤质分析表 where 日期='" + qsrq + "'";

                DataTable dtmt = DBsql.RunDataTable(sql, out errMsg);

                if (dtmt.Rows.Count > 0)
                {
                    if (dtmt.Rows.Count == 1)
                    {
                        mz1ml1 = dtmt.Rows[0]["煤量1"].ToString();
                        mz2ml1 = dtmt.Rows[0]["煤量2"].ToString();

                        dwfrl1 = dtmt.Rows[0]["低位发热量"].ToString();
                    }
                    else if (dtmt.Rows.Count == 2)
                    {
                        mz1ml1 = dtmt.Rows[0]["煤量1"].ToString();
                        mz1ml2 = dtmt.Rows[1]["煤量1"].ToString();
                        mz2ml1 = dtmt.Rows[0]["煤量2"].ToString();
                        mz2ml2 = dtmt.Rows[1]["煤量2"].ToString();

                        dwfrl1 = dtmt.Rows[0]["低位发热量"].ToString();
                        dwfrl2 = dtmt.Rows[1]["低位发热量"].ToString();
                    }
                    else if (dtmt.Rows.Count == 3)
                    {
                        mz1ml1 = dtmt.Rows[0]["煤量1"].ToString();
                        mz1ml2 = dtmt.Rows[1]["煤量1"].ToString();
                        mz1ml3 = dtmt.Rows[2]["煤量1"].ToString();
                        mz2ml1 = dtmt.Rows[0]["煤量2"].ToString();
                        mz2ml2 = dtmt.Rows[1]["煤量2"].ToString();
                        mz2ml3 = dtmt.Rows[2]["煤量2"].ToString();

                        dwfrl1 = dtmt.Rows[0]["低位发热量"].ToString();
                        dwfrl2 = dtmt.Rows[1]["低位发热量"].ToString();
                        dwfrl3 = dtmt.Rows[2]["低位发热量"].ToString();
                    }

                }


                //string sqlCmd = "SELECT 低位热值 FROM 入炉煤质日数据表 where 日期='" + Convert.ToDateTime(qsrq).ToShortDateString() + "'";

                //object objrlm = DBsql.RunSingle(sqlCmd, out errMsg);

                //if (objrlm == null)
                //{
                //    string sql = "select * from 入炉煤质分析表 where 日期='" + qsrq + "'";

                //    DataTable dtmt = DBsql.RunDataTable(sql, out errMsg);

                //    #region
                //    if (dtmt.Rows.Count > 0)
                //    {
                //        if (dtmt.Rows.Count == 1)
                //        {
                //            mz1ml1 = dtmt.Rows[0]["煤量1"].ToString();
                //            mz2ml1 = dtmt.Rows[0]["煤量2"].ToString();

                //            dwfrl1 = dtmt.Rows[0]["低位发热量"].ToString();
                //        }
                //        else if (dtmt.Rows.Count == 2)
                //        {
                //            mz1ml1 = dtmt.Rows[0]["煤量1"].ToString();
                //            mz1ml2 = dtmt.Rows[1]["煤量1"].ToString();
                //            mz2ml1 = dtmt.Rows[0]["煤量2"].ToString();
                //            mz2ml2 = dtmt.Rows[1]["煤量2"].ToString();

                //            dwfrl1 = dtmt.Rows[0]["低位发热量"].ToString();
                //            dwfrl2 = dtmt.Rows[1]["低位发热量"].ToString();
                //        }
                //        else if (dtmt.Rows.Count == 3)
                //        {
                //            mz1ml1 = dtmt.Rows[0]["煤量1"].ToString();
                //            mz1ml2 = dtmt.Rows[1]["煤量1"].ToString();
                //            mz1ml3 = dtmt.Rows[2]["煤量1"].ToString();
                //            mz2ml1 = dtmt.Rows[0]["煤量2"].ToString();
                //            mz2ml2 = dtmt.Rows[1]["煤量2"].ToString();
                //            mz2ml3 = dtmt.Rows[2]["煤量2"].ToString();

                //            dwfrl1 = dtmt.Rows[0]["低位发热量"].ToString();
                //            dwfrl2 = dtmt.Rows[1]["低位发热量"].ToString();
                //            dwfrl3 = dtmt.Rows[2]["低位发热量"].ToString();
                //        }

                //    }
                //    #endregion

                //    try
                //    {
                //        mon = "((" + dwfrl1 + "*((" + mz1ml1 + ")+(" + mz2ml1 + ")))+(" + dwfrl1 + "*((" + mz1ml2 + ")+(" + mz2ml2 + ")))+(" + dwfrl3 + "*((" + mz1ml3 + ")+(" + mz2ml3 + "))))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + ")+(" + mz2ml1 + ") + (" + mz2ml2 + ") + (" + mz2ml3 + "))";
                //        re = StrHelper.Cale(mon);
                //        re = StrHelper.checkCatch(re);
                //        res = double.Parse(re.ToString()) / 3;
                //    }
                //    catch
                //    { res = 0; }
                //}
                //else
                //    res = double.Parse(objrlm.ToString()) / 3;
            }
            else if (repType == "日报")
            {
                string sqlCmd = "SELECT 低位热值 FROM 入炉煤质日数据表 where 日期='" + Convert.ToDateTime(qsrq).ToShortDateString() + "'";

                object objrlm = DBsql.RunSingle(sqlCmd, out errMsg);

                if (objrlm == null)
                {
                    string sql = "select * from 入炉煤质分析表 where 日期='" + qsrq + "'";

                    DataTable dtmt = DBsql.RunDataTable(sql, out errMsg);

                    #region
                    if (dtmt.Rows.Count > 0)
                    {
                        if (dtmt.Rows.Count == 1)
                        {
                            mz1ml1 = dtmt.Rows[0]["煤量1"].ToString();
                            mz2ml1 = dtmt.Rows[0]["煤量2"].ToString();

                            dwfrl1 = dtmt.Rows[0]["低位发热量"].ToString();
                        }
                        else if (dtmt.Rows.Count == 2)
                        {
                            mz1ml1 = dtmt.Rows[0]["煤量1"].ToString();
                            mz1ml2 = dtmt.Rows[1]["煤量1"].ToString();
                            mz2ml1 = dtmt.Rows[0]["煤量2"].ToString();
                            mz2ml2 = dtmt.Rows[1]["煤量2"].ToString();

                            dwfrl1 = dtmt.Rows[0]["低位发热量"].ToString();
                            dwfrl2 = dtmt.Rows[1]["低位发热量"].ToString();
                        }
                        else if (dtmt.Rows.Count == 3)
                        {
                            mz1ml1 = dtmt.Rows[0]["煤量1"].ToString();
                            mz1ml2 = dtmt.Rows[1]["煤量1"].ToString();
                            mz1ml3 = dtmt.Rows[2]["煤量1"].ToString();
                            mz2ml1 = dtmt.Rows[0]["煤量2"].ToString();
                            mz2ml2 = dtmt.Rows[1]["煤量2"].ToString();
                            mz2ml3 = dtmt.Rows[2]["煤量2"].ToString();

                            dwfrl1 = dtmt.Rows[0]["低位发热量"].ToString();
                            dwfrl2 = dtmt.Rows[1]["低位发热量"].ToString();
                            dwfrl3 = dtmt.Rows[2]["低位发热量"].ToString();
                        }

                    }
                    #endregion

                    try
                    {
                        mon = "((" + dwfrl1 + "*((" + mz1ml1 + ")+(" + mz2ml1 + ")))+(" + dwfrl2 + "*((" + mz1ml2 + ")+(" + mz2ml2 + ")))+(" + dwfrl3 + "*((" + mz1ml3 + ")+(" + mz2ml3 + "))))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + ")+(" + mz2ml1 + ") + (" + mz2ml2 + ") + (" + mz2ml3 + "))";
                        re = StrHelper.Cale(mon);
                        re = StrHelper.checkCatch(re);
                        res = double.Parse(re.ToString());
                    }
                    catch
                    { res = 0; }

                }
                else
                    res = double.Parse(objrlm.ToString());
            }
            else if (repType == "月报" || repType == "年报")
            {
                string[] date = sh.DateDiff(DateTime.Parse(qsrq), DateTime.Parse(jsrq));

                for (int i = 0; i < date.Length - 1; i++)
                {
                    string sql = "SELECT SUM(低位热值) FROM 入炉煤质日数据表 where 日期>='" + DateTime.Parse(date[i]).ToString("yyyy-MM-dd 0:00:00") + "' and  日期<'" + DateTime.Parse(date[i]).ToString("yyyy-MM-dd 23:59:59") + "'";

                    object objrlm = DBsql.RunSingle(sql, out errMsg);

                    if (objrlm == null || objrlm.ToString() == "")
                    {
                        sql = "select * from 入炉煤质分析表 where 日期='" + DateTime.Parse(date[i]).ToString("yyyy-MM-dd 0:00:00") + "'";

                        DataTable dtmt = DBsql.RunDataTable(sql, out errMsg);

                        #region
                        if (dtmt.Rows.Count > 0)
                        {
                            if (dtmt.Rows.Count == 1)
                            {
                                mz1ml1 = dtmt.Rows[0]["煤量1"].ToString();
                                mz2ml1 = dtmt.Rows[0]["煤量2"].ToString();

                                dwfrl1 = dtmt.Rows[0]["低位发热量"].ToString();
                            }
                            else if (dtmt.Rows.Count == 2)
                            {
                                mz1ml1 = dtmt.Rows[0]["煤量1"].ToString();
                                mz1ml2 = dtmt.Rows[1]["煤量1"].ToString();
                                mz2ml1 = dtmt.Rows[0]["煤量2"].ToString();
                                mz2ml2 = dtmt.Rows[1]["煤量2"].ToString();

                                dwfrl1 = dtmt.Rows[0]["低位发热量"].ToString();
                                dwfrl2 = dtmt.Rows[1]["低位发热量"].ToString();
                            }
                            else if (dtmt.Rows.Count == 3)
                            {
                                mz1ml1 = dtmt.Rows[0]["煤量1"].ToString();
                                mz1ml2 = dtmt.Rows[1]["煤量1"].ToString();
                                mz1ml3 = dtmt.Rows[2]["煤量1"].ToString();
                                mz2ml1 = dtmt.Rows[0]["煤量2"].ToString();
                                mz2ml2 = dtmt.Rows[1]["煤量2"].ToString();
                                mz2ml3 = dtmt.Rows[2]["煤量2"].ToString();

                                dwfrl1 = dtmt.Rows[0]["低位发热量"].ToString();
                                dwfrl2 = dtmt.Rows[1]["低位发热量"].ToString();
                                dwfrl3 = dtmt.Rows[2]["低位发热量"].ToString();
                            }

                        }
                        #endregion

                        try
                        {
                            mon = "((" + dwfrl1 + "*((" + mz1ml1 + ")+(" + mz2ml1 + ")))+(" + dwfrl2 + "*((" + mz1ml2 + ")+(" + mz2ml2 + ")))+(" + dwfrl3 + "*((" + mz1ml3 + ")+(" + mz2ml3 + "))))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + ")+(" + mz2ml1 + ") + (" + mz2ml2 + ") + (" + mz2ml3 + "))";
                            re = StrHelper.Cale(mon);
                            re = StrHelper.checkCatch(re);
                        }
                        catch
                        { re = "0"; }

                        string re1 = "";
                        try
                        {
                            mon = "((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + ")+(" + mz2ml1 + ") + (" + mz2ml2 + ") + (" + mz2ml3 + "))";
                            re1 = StrHelper.Cale(mon);
                            re1 = StrHelper.checkCatch(re1);
                        }
                        catch
                        { re1 = "0"; }

                        val1 += "(" + re + "*" + re1 + ")+";
                        val2 += "(" + re1 + ")+";
                    }
                    else
                    {
                        sql = "select sum(煤量1)+sum(煤量2) from 入炉煤质分析表 where 日期='" + DateTime.Parse(date[i]).ToShortDateString() + "'";

                        objML1 = DBsql.RunSingle(sql, out errMsg);

                        val1 += "(" + objrlm.ToString() + "*" + objML1.ToString() + ")+";
                        val2 += "(" + objML1.ToString() + ")+";
                    }
                }


                val = "(" + val1.TrimEnd('+') + ")/(" + val2.TrimEnd('+') + ")";

                try
                {
                    re = StrHelper.Cale(val);
                    re = StrHelper.checkCatch(re);
                }
                catch { re = "0"; }
                res = double.Parse(re);
            }

            return res.ToString();
        }

        public string rlmdwfrl(string repType, string qsrq, string jsrq, int unit, string bz)
        {
            string val = "";

            if (repType == "值报")
            {
                string sql = "select 低位发热量 from 入炉煤质分析表 where 日期='" + qsrq + "' and 班值=" + bz;

                object obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null && obj.ToString() != "")
                { val = obj.ToString(); }
                else { val = "0"; }
            }

            return val;
        }

        /// <summary>
        /// 过热器平均减温水量
        /// </summary>
        /// <param name="repName">报表名称</param>
        /// <param name="repType">报表类型</param>
        /// <param name="qsrq">起始</param>
        /// <param name="jsrq">结束</param>
        /// <param name="unit">0全厂</param>
        /// <param name="jy">机组运行小时</param>
        /// <returns></returns>
        public string AvgSuperheaterTempOfWater(string repName, string repType, string qsrq, string jsrq, int unit, string jy)
        {
            int ret = -1;
            string res = "";
            string sqlCmd = "";
            string tagName = "";
            double zhqDiff = 0;

            sqlCmd = " SELECT 累计点  FROM T_Sheet_SheetPara WHERE (参数名='过热器减温水量累计') and (机组=" + unit + ") and (报表名称 = '" + repName + "')";

            tagName = DBsql.RunSingle(sqlCmd, out errMsg).ToString();

            //过热器减温水量累计/运行小时
            if (repType == "值报")
            {
                ek.GetHisDiffValue(tagName, qsrq, jsrq, ref ret, ref zhqDiff);

                mon = zhqDiff.ToString() + "/" + jy;

                try
                { res = StrHelper.Cale(mon); }
                catch { res = "0"; }

                res = StrHelper.checkCatch(res);

            }
            else if (repType == "日报")
            {
                ek.GetHisDiffValue(tagName, qsrq, jsrq, ref ret, ref zhqDiff);

                mon = zhqDiff.ToString() + "/" + jy;

                try
                { res = StrHelper.Cale(mon); }
                catch { res = "0"; }

                res = StrHelper.checkCatch(res);

            }
            else if (repType == "月报")
            {
                ek.GetHisDiffValue(tagName, qsrq, jsrq, ref ret, ref zhqDiff);

                mon = zhqDiff.ToString() + "/" + jy;

                try
                { res = StrHelper.Cale(mon); }
                catch { res = "0"; }

                res = StrHelper.checkCatch(res);

            }
            else if (repType == "年报")
            {
                ek.GetHisDiffValue(tagName, qsrq, jsrq, ref ret, ref zhqDiff);

                mon = zhqDiff.ToString() + "/" + jy;

                try
                { res = StrHelper.Cale(mon); }
                catch { res = "0"; }

                res = StrHelper.checkCatch(res);

            }
            return res;
        }

        /// <summary>
        /// 入炉煤量
        /// </summary>
        /// <param name="repName">报表名称</param>
        /// <param name="repType">报表类型</param>
        /// <param name="qsrq">起始日期</param>
        /// <param name="jsrq">结束日期</param>
        /// <param name="unit">0全厂</param>
        /// <param name="bZhi">班值</param>
        /// <returns></returns>
        public string CoaIntoFurnace(string repName, string repType, string qsrq, string jsrq, int unit, string bZhi)
        {
            object obj;
            string sql = "";
            string res = "";

            if (repType == "值报")
            {
                string ml = "";

                if (unit == 1)
                    ml = "煤量1";
                else if (unit == 2)
                    ml = "煤量2";

                sql = "select " + ml + " from 入炉煤质分析表 where 日期='" + DateTime.Parse(qsrq).ToShortDateString() + "' and 班值=" + int.Parse(bZhi);

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }
            else if (repType == "日报")
            {
                if (unit == 1)
                    sql = "select sum(煤量1)  from 入炉煤质分析表  where 日期 = '" + qsrq + "'";
                else if (unit == 2)
                    sql = "select sum(煤量2)  from 入炉煤质分析表  where 日期 = '" + qsrq + "'";
                else
                    sql = "select sum((煤量1+煤量2))/sum(煤量1+煤量2)   from 入炉煤质分析表 where 日期 = '" + qsrq + "'";

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }
            else if (repType == "月报")
            {
                if (unit == 1)
                    sql = "select sum(煤量1)   from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else if (unit == 2)
                    sql = "select sum(煤量2)  from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else
                    sql = "select sum((煤量1+煤量2))   from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }
            else if (repType == "年报")
            {
                if (unit == 1)
                    sql = "select sum(煤量1)   from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else if (unit == 2)
                    sql = "select sum(煤量2)  from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else
                    sql = "select sum((煤量1+煤量2))   from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }

            return res;
        }

        /// <summary>
        /// 飞灰可燃物
        /// </summary>
        /// <param name="repName">报表名称</param>
        /// <param name="repType">报表类型</param>
        /// <param name="qsrq">起始日期</param>
        /// <param name="jsrq">结束日期</param>
        /// <param name="unit">0全厂</param>
        /// <param name="bZhi">班值</param>
        /// <returns></returns>
        public string FlyAshCombustibles(string repName, string repType, string qsrq, string jsrq, int unit, string bZhi)
        {
            object obj;
            string sql = "";
            string res = "";

            if (repType == "值报")
            {
                string hfkrw = "";

                if (unit == 1)
                    hfkrw = "飞灰可燃物1";
                else if (unit == 2)
                    hfkrw = "飞灰可燃物2";

                sql = "select " + hfkrw + " from 入炉煤质分析表 where 日期='" + DateTime.Parse(qsrq).ToShortDateString() + "' and 班值=" + int.Parse(bZhi);

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }
            else if (repType == "日报")
            {
                if (unit == 1)
                    sql = "select sum(飞灰可燃物1*煤量1)/sum(煤量1)  from 入炉煤质分析表 where 日期 = '" + qsrq + "'";
                else if (unit == 2)
                    sql = "select sum(飞灰可燃物2*煤量2)/sum(煤量2)  from 入炉煤质分析表 where 日期 = '" + qsrq + "'";
                else
                    sql = "select sum(飞灰可燃物1*煤量1+飞灰可燃物2*煤量2)/sum(煤量1+煤量2)  from 入炉煤质分析表 where 日期 = '" + qsrq + "'";

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }
            else if (repType == "月报")
            {
                if (unit == 1)
                    sql = "select sum(飞灰可燃物1*煤量1)/sum(煤量1)  from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else if (unit == 2)
                    sql = "select sum(飞灰可燃物2*煤量2)/sum(煤量2)  from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else
                    sql = "select sum(飞灰可燃物1*煤量1+飞灰可燃物2*煤量2)/sum(煤量1+煤量2)  from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }
            else if (repType == "年报")
            {
                if (unit == 1)
                    sql = "select sum(飞灰可燃物1*煤量1)/sum(煤量1)  from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else if (unit == 2)
                    sql = "select sum(飞灰可燃物2*煤量2)/sum(煤量2)  from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else
                    sql = "select sum(飞灰可燃物1*煤量1+飞灰可燃物2*煤量2)/sum(煤量1+煤量2)  from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }

            return res;
        }

        /// <summary>
        /// 入炉煤灰份
        /// </summary>
        /// <param name="repName">报表名称</param>
        /// <param name="repType">报表类型</param>
        /// <param name="qsrq">起始日期</param>
        /// <param name="jsrq">结束日期</param>
        /// <param name="unit">0全厂</param>
        /// <param name="bZhi">班值</param>
        /// <returns></returns>
        public string rlmhf(string repName, string repType, string qsrq, string jsrq, int unit, string bZhi)
        {
            object obj;
            string sql = "";
            string res = "";

            if (repType == "值报")
            {
                sql = "select 灰份 from 入炉煤质分析表 where 日期='" + DateTime.Parse(qsrq).ToShortDateString() + "' and 班值=" + int.Parse(bZhi);

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }
            else if (repType == "日报")
            {
                if (unit == 1)
                    sql = "select sum(灰份*(煤量1))/sum(煤量1)  from 入炉煤质分析表  where 日期 = '" + qsrq + "'";
                else if (unit == 2)
                    sql = "select sum(灰份*(煤量2))/sum(煤量2)  from 入炉煤质分析表  where 日期 = '" + qsrq + "'";
                else
                    sql = "select sum(灰份*(煤量1+煤量2))/sum(煤量1+煤量2)   from 入炉煤质分析表 where 日期 = '" + qsrq + "'";

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }
            else if (repType == "月报")
            {
                //select sum(内在水份*(煤量1))/sum(煤量1)  from 入炉煤质分析表 where 日期 between '2011-11-8 00:00:00' and '2011-11-10 00:00:00'
                if (unit == 1)
                    sql = "select sum(灰份*(煤量1))/sum(煤量1)   from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else if (unit == 2)
                    sql = "select sum(灰份*(煤量2))/sum(煤量2)  from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else
                    sql = "select sum(灰份*(煤量1+煤量2))/sum(煤量1+煤量2)   from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }
            else if (repType == "年报")
            {
                if (unit == 1)
                    sql = "select sum(灰份*(煤量1))/sum(煤量1)   from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else if (unit == 2)
                    sql = "select sum(灰份*(煤量2))/sum(煤量2)  from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else
                    sql = "select sum(灰份*(煤量1+煤量2))/sum(煤量1+煤量2)   from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }

            return res;
        }


        /// <summary>
        /// 入炉煤挥发份
        /// </summary>
        /// <param name="repName">报表名称</param>
        /// <param name="repType">报表类型</param>
        /// <param name="qsrq">起始日期</param>
        /// <param name="jsrq">结束日期</param>
        /// <param name="unit">0全厂</param>
        /// <param name="bZhi">班值</param>
        /// <returns></returns>
        public string rlmhff(string repName, string repType, string qsrq, string jsrq, int unit, string bZhi)
        {
            object obj;
            string sql = "";
            string res = "";

            if (repType == "值报")
            {
                sql = "select 挥发份 from 入炉煤质分析表 where 日期='" + DateTime.Parse(qsrq).ToShortDateString() + "' and 班值=" + int.Parse(bZhi);

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }
            else if (repType == "日报")
            {
                if (unit == 1)
                    sql = "select sum(挥发份*(煤量1))/sum(煤量1)  from 入炉煤质分析表  where 日期 = '" + qsrq + "'";
                else if (unit == 2)
                    sql = "select sum(挥发份*(煤量2))/sum(煤量2)  from 入炉煤质分析表  where 日期 = '" + qsrq + "'";
                else
                    sql = "select sum(挥发份*(煤量1+煤量2))/sum(煤量1+煤量2)   from 入炉煤质分析表 where 日期 = '" + qsrq + "'";

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }
            else if (repType == "月报")
            {
                //select sum(内在水份*(煤量1))/sum(煤量1)  from 入炉煤质分析表 where 日期 between '2011-11-8 00:00:00' and '2011-11-10 00:00:00'
                if (unit == 1)
                    sql = "select sum(挥发份*(煤量1))/sum(煤量1)   from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else if (unit == 2)
                    sql = "select sum(挥发份*(煤量2))/sum(煤量2)  from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else
                    sql = "select sum(挥发份*(煤量1+煤量2))/sum(煤量1+煤量2)   from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }
            else if (repType == "年报")
            {
                if (unit == 1)
                    sql = "select sum(挥发份*(煤量1))/sum(煤量1)   from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else if (unit == 2)
                    sql = "select sum(挥发份*(煤量2))/sum(煤量2)  from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else
                    sql = "select sum(挥发份*(煤量1+煤量2))/sum(煤量1+煤量2)   from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }


            return res;
        }

        /// <summary>
        /// 内水
        /// 值报没有内水,因为锅炉效率可以直接通过小时点计算
        /// 其它报表需要内水做锅炉效率计算
        /// </summary>
        /// <param name="repName"></param>
        /// <param name="repType"></param>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public string ns(string repName, string repType, string qsrq, string jsrq, int unit)
        {
            object obj;
            string sql = "";
            string res = "";
            if (repType == "日报")
            {
                if (unit == 1)
                    sql = "select sum(内在水份*(煤量1))/sum(煤量1)  from 入炉煤质分析表  where 日期 = '" + qsrq + "'";
                else if (unit == 2)
                    sql = "select sum(内在水份*(煤量2))/sum(煤量2)  from 入炉煤质分析表  where 日期 = '" + qsrq + "'";
                else
                    sql = "select sum(内在水份*(煤量1+煤量2))/sum(煤量1+煤量2)   from 入炉煤质分析表 where 日期 = '" + qsrq + "'";

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }
            else if (repType == "月报")
            {
                //select sum(内在水份*(煤量1))/sum(煤量1)  from 入炉煤质分析表 where 日期 between '2011-11-8 00:00:00' and '2011-11-10 00:00:00'
                if (unit == 1)
                    sql = "select sum(内在水份*(煤量1))/sum(煤量1)   from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else if (unit == 2)
                    sql = "select sum(内在水份*(煤量2))/sum(煤量2)  from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else
                    sql = "select sum(内在水份*(煤量1+煤量2))/sum(煤量1+煤量2)   from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }
            else if (repType == "年报")
            {
                if (unit == 1)
                    sql = "select sum(内在水份*(煤量1))/sum(煤量1)   from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else if (unit == 2)
                    sql = "select sum(内在水份*(煤量2))/sum(煤量2)  from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else
                    sql = "select sum(内在水份*(煤量1+煤量2))/sum(煤量1+煤量2)   from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }
            return res;
        }

        /// <summary>
        /// 全水 理由同内水
        /// </summary>
        /// <param name="repName"></param>
        /// <param name="repType"></param>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public string qs(string repName, string repType, string qsrq, string jsrq, int unit)
        {
            object obj;
            string sql = "";
            string res = "";
            if (repType == "日报")
            {
                if (unit == 1)
                    sql = "select sum(全水份*(煤量1))/sum(煤量1)  from 入炉煤质分析表  where 日期 = '" + qsrq + "'";
                else if (unit == 2)
                    sql = "select sum(全水份*(煤量2))/sum(煤量2)  from 入炉煤质分析表  where 日期 = '" + qsrq + "'";
                else
                    sql = "select sum(全水份*(煤量1+煤量2))/sum(煤量1+煤量2)   from 入炉煤质分析表 where 日期 = '" + qsrq + "'";

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }
            else if (repType == "月报")
            {
                //select sum(内在水份*(煤量1))/sum(煤量1)  from 入炉煤质分析表 where 日期 between '2011-11-8 00:00:00' and '2011-11-10 00:00:00'
                if (unit == 1)
                    sql = "select sum(全水份*(煤量1))/sum(煤量1)   from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else if (unit == 2)
                    sql = "select sum(全水份*(煤量2))/sum(煤量2)  from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else
                    sql = "select sum(全水份*(煤量1+煤量2))/sum(煤量1+煤量2)   from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }
            else if (repType == "年报")
            {
                if (unit == 1)
                    sql = "select sum(全水份*(煤量1))/sum(煤量1)   from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else if (unit == 2)
                    sql = "select sum(全水份*(煤量2))/sum(煤量2)  from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";
                else
                    sql = "select sum(全水份*(煤量1+煤量2))/sum(煤量1+煤量2)   from 入炉煤质分析表 where 日期 >= '" + qsrq + "' and 日期 < '" + jsrq + "'";

                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    res = obj.ToString();
                else
                    res = "0";
            }
            return res;
        }

        /// <summary>
        /// 排烟氧量
        /// </summary>
        /// <param name="repName">报表名称</param>
        /// <param name="repType">报表类型</param>
        /// <param name="qsrq">起始日期</param>
        /// <param name="jsrq">结束日期</param>
        /// <param name="unit">机组</param>
        /// <returns></returns>
        public string pyyl(string repName, string repType, string qsrq, string jsrq, int unit)
        {
            string mon = "";
            string res = "";

            if (repType == "值报")
            {
                object obj;
                string sql;
                int ret = -1;
                double value = 0;
                string pName = "";

                jsrq = Convert.ToDateTime(jsrq).AddSeconds(-1).ToString();

                sql = "select 数值 from 氧量数据表 where 时间='" + jsrq + "'and 机组=" + unit;
                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                { res = obj.ToString(); }
                else
                {
                    sql = "select 小时点 from T_Sheet_SheetPara where 报表名称='" + repName + "' and 参数名='炉烟含氧量' and 机组=" + unit;
                    obj = DBsql.RunSingle(sql, out errMsg);

                    if (obj != null)
                        pName = obj.ToString();

                    ek.GetHisValue(pName, jsrq, ref ret, ref value);

                    res = value.ToString();
                }

            }
            else if (repType == "日报")
            {
                object obj;
                string sql;
                int ret = -1;
                double value = 0;
                string pName = "";

                jsrq = Convert.ToDateTime(jsrq).AddSeconds(-1).ToString();

                sql = "select 数值 from 氧量数据表 where 时间='" + jsrq + "'and 机组=" + unit;
                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                { res = obj.ToString(); }
                else
                {
                    sql = "select 日点 from T_Sheet_SheetPara where 报表名称='" + repName + "' and 参数名='炉烟含氧量' and 机组=" + unit;
                    obj = DBsql.RunSingle(sql, out errMsg);

                    if (obj != null)
                        pName = obj.ToString();

                    ek.GetHisValue(pName, jsrq, ref ret, ref value);

                    res = value.ToString();
                }

            }
            else if (repType == "月报")
            {
                object obj;
                string sql;
                int ret = -1;
                double value = 0;
                string pName = "";

                string[] date = sh.DateDiff(DateTime.Parse(qsrq), DateTime.Parse(jsrq));

                if (date == null)
                {
                    jsrq = Convert.ToDateTime(jsrq).AddSeconds(-1).ToString();

                    sql = "select 数值 from 氧量数据表 where 时间='" + jsrq + "'and 机组=" + unit;
                    obj = DBsql.RunSingle(sql, out errMsg);

                    if (obj != null)
                    { res = obj.ToString(); }
                    else
                    {
                        sql = "select 日点 from T_Sheet_SheetPara where 报表名称='" + repName + "' and 参数名='炉烟含氧量' and 机组=" + unit;
                        obj = DBsql.RunSingle(sql, out errMsg);

                        if (obj != null)
                            pName = obj.ToString();

                        ek.GetHisValue(pName, jsrq, ref ret, ref value);

                        res = value.ToString();
                    }
                }
                else
                {
                    int sum = date.Length - 1;

                    for (int i = 0; i < sum; i++)
                    {
                        jsrq = Convert.ToDateTime(date[i]).AddSeconds(-1).ToString();

                        sql = "select 数值 from 氧量数据表 where 时间='" + jsrq + "' and 机组=" + unit;
                        obj = DBsql.RunSingle(sql, out errMsg);

                        if (obj != null)
                        { res = obj.ToString(); }
                        else
                        {
                            sql = "select 日点 from T_Sheet_SheetPara where 报表名称='" + repName + "' and 参数名='炉烟含氧量' and 机组=" + unit;
                            obj = DBsql.RunSingle(sql, out errMsg);

                            if (obj != null)
                                pName = obj.ToString();

                            ek.GetHisValue(pName, jsrq, ref ret, ref value);

                            res = value.ToString();
                        }
                        mon += "(" + res + ")+";
                    }

                    mon = "(" + mon.TrimEnd('+') + ")/" + sum;

                    try
                    { res = StrHelper.Cale(mon); }
                    catch { res = "0"; }
                }
                res = StrHelper.checkCatch(res);
            }
            else if (repType == "年报")
            {
                object obj;
                string sql;
                int ret = -1;
                double value = 0;
                string pName = "";

                string[] date = sh.DateDiff(DateTime.Parse(qsrq), DateTime.Parse(jsrq));

                int sum = date.Length - 1;

                for (int i = 0; i < sum; i++)
                {
                    jsrq = Convert.ToDateTime(date[i]).AddSeconds(-1).ToString();

                    sql = "select 数值 from 氧量数据表 where 时间='" + jsrq + "' and 机组=" + unit;
                    obj = DBsql.RunSingle(sql, out errMsg);

                    if (obj != null)
                    { res = obj.ToString(); }
                    else
                    {
                        sql = "select 日点 from T_Sheet_SheetPara where 报表名称='" + repName + "' and 参数名='炉烟含氧量' and 机组=" + unit;
                        obj = DBsql.RunSingle(sql, out errMsg);

                        if (obj != null)
                            pName = obj.ToString();

                        ek.GetHisValue(pName, jsrq, ref ret, ref value);

                        res = value.ToString();
                    }
                    mon += "(" + res + ")+";
                }
                mon = "(" + mon.TrimEnd('+') + ")/" + sum;

                try
                { res = StrHelper.Cale(mon); }
                catch { res = "0"; }

                res = StrHelper.checkCatch(res);
            }
            return res;
        }


        /// <summary>
        /// 锅炉效率
        /// </summary>
        /// <param name="repName">报表名称</param>
        /// <param name="repType">报表类型</param>
        /// <param name="qsrq">起始日期</param>
        /// <param name="jsrq">结束日期</param>
        /// <param name="unit">机组</param>
        /// <param name="pyyl">排烟氧量</param>
        /// <param name="rlmdwfrl">入炉煤低位发热量</param>
        /// <param name="jy">机组运行小时</param>
        /// <param name="zhq">主蒸汽流量累计</param>
        /// <param name="fhkrw">飞灰可燃物</param>
        /// <param name="hf">灰份</param>
        /// <param name="hf">班值</param>
        /// <returns></returns>
        public string glxl(string repName, string repType, string qsrq, string jsrq, int unit, string pyyl, string rlmdwfrl, string jy, string zhq, string fhkrw, string hf, string bZhi)
        {
            string glPYyl = pyyl;   //O2  排烟氧量
            string glPYwd = "0";   //Tpy 排烟温度
            string glSFwd = "0";   //Tlk 送风机出口温度
            string Qdw = rlmdwfrl;  //Qdw 煤低位发热量
            string glNS = "";       //Mad 内水
            string glQS = "";       //Mar 全水
            string glJHFkg = hf;    //Aad 空干基灰份
            string Cfhb = "0.82";   //Cfhb 飞灰比热
            string Clzb = "0.96";   //Clzb 炉渣比热
            string Cfh = fhkrw;       //Cfh 飞灰含碳量
            string Clz = "3";       //Clz 炉渣含碳量
            string glxl = "";       //Eta_b 锅炉效率
            string Q2 = "";
            string Q3 = "0.3";
            string Q4 = "";
            string Q5 = "";
            string Q6 = "";

            if (repType == "值报")
            {
                #region
                object obj;
                int ret = 0;
                double val = 0;
                string sql = "";
                string value = "";
                string pName = "";

                //排烟温度
                sql = "select 小时点 from T_Sheet_SheetPara where 参数名='排烟温度' and 报表名称='" + repName + "' and 机组=" + unit;
                obj = DBsql.RunSingle(sql, out errMsg);
                if (obj != null)
                    pName = obj.ToString();

                ek.GetHisValue(pName, jsrq, ref ret, ref val);

                glPYwd = val.ToString();

                //送风机出口温度
                sql = "select 小时点 from T_Sheet_SheetPara where 参数名='送风机出口温度' and 报表名称='" + repName + "' and 机组=" + unit;
                obj = DBsql.RunSingle(sql, out errMsg);
                if (obj != null)
                    pName = obj.ToString();

                ek.GetHisValue(pName, jsrq, ref ret, ref val);

                glSFwd = val.ToString();

                ///单算 内水+全水
                sql = "select 内在水份 from 入炉煤质分析表 where 日期='" + DateTime.Parse(qsrq).ToShortDateString() + "' and 班值=" + int.Parse(bZhi);
                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    value = obj.ToString();
                else
                    value = "0";

                //Mad 内水
                glNS = value;

                sql = "select 全水份 from 入炉煤质分析表 where 日期='" + DateTime.Parse(qsrq).ToShortDateString() + "' and 班值=" + int.Parse(bZhi);
                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj != null)
                    value = obj.ToString();
                else
                    value = "0";

                //Mar 全水
                glQS = value;

                try
                {
                    string strQ2 = "((0.9657+0.0005*(" + glPYwd + ")-0.000001*(" + glPYwd + ")*(" + glPYwd + "))/(" + Qdw + ")*((0.0576+0.02337*(" + Qdw + ")/1000)+(0.699+0.303*(" + Qdw + ")/1000)*(21/(21-(" + glPYyl + "))))*((" + glPYwd + ")-(" + glSFwd + "))*100)+(188/(" + Qdw + ")*((0.9081-0.0163*(" + Qdw + ")/1000)+0.01*((0.0089*(" + Qdw + ")/1000-0.0139)+(0.699+0.303*(" + Qdw + ")/1000)*(21/(21-(" + glPYyl + ")))))*((" + glPYwd + ")-(" + glSFwd + ")))";

                    Q2 = StrHelper.Cale(strQ2);
                    Q2 = StrHelper.checkCatch(Q2);

                    string strQ4 = "337.27*((100-(" + glQS + "))/(100-(" + glNS + "))*(" + glJHFkg + "))*(10*(" + Clz + ")/(100-(" + Clz + "))+90*(" + Cfh + ")/(100-(" + Cfh + ")))/(" + Qdw + ")";

                    Q4 = StrHelper.Cale(strQ4);
                    Q4 = StrHelper.checkCatch(Q4);

                    string strQ5 = "5.82*111.03/((" + zhq + ")/(" + jy + "))";//锅炉蒸发量累计/运行小时=主蒸汽流量  (锅炉蒸发量累计=主蒸汽流量)

                    //string strQ5 = "5.82*111.03/1991";//锅炉蒸发量累计/运行小时=主蒸汽流量

                    Q5 = StrHelper.Cale(strQ5);
                    Q5 = StrHelper.checkCatch(Q5);
                    string strQ6 = "(10*(800-(" + glSFwd + "))*(" + Clzb + ")/(100-(" + Clzb + "))+90*((" + glPYwd + ")-(" + glSFwd + "))*(" + Cfhb + ")/(100-(" + Cfhb + ")))*((100-(" + glQS + "))/(100-(" + glNS + "))*(" + glJHFkg + "))/100/(" + Qdw + ")";

                    Q6 = StrHelper.Cale(strQ6);
                    Q6 = StrHelper.checkCatch(Q6);

                }
                catch (Exception ce)
                {
                    glxl = "0";
                }

                if (glxl != "0")
                {
                    try
                    { glxl = StrHelper.Cale("100-(" + Q2 + ")-(" + Q3 + ")-(" + Q4 + ")-(" + Q5 + ")-(" + Q6 + ")"); }
                    catch { glxl = "0"; }
                }
                #endregion
            }

            return "Q2+" + Q2 + ";Q4+" + Q4 + ";Q5+" + Q5 + ";Q6+" + Q6 + ";glxl+" + glxl;
        }


        public string glxl(string repName, string repType, string qsrq, string jsrq, int unit, string pyyl, string rlmdwfrl, string jy, string zhq, string hfkrw, string hf, string ns, string qs, string tjxsA, string tjxsB)
        {
            string glPYyl = pyyl;   //O2  排烟氧量
            string glPYwd = "0";    //Tpy 排烟温度
            string glSFwd = "0";    //Tlk 送风机出口温度
            string Qdw = rlmdwfrl;  //Qdw 煤低位发热量
            string glNS = ns;       //Mad 内水
            string glQS = qs;       //Mar 全水
            string glJHFkg = hf;    //Aad 空干基灰份
            string Cfhb = "0.82";   //Cfhb 飞灰比热
            string Clzb = "0.96";   //Clzb 炉渣比热
            string Cfh = hfkrw;     //Cfh 飞灰含碳量
            string Clz = "3";       //Clz 炉渣含碳量
            string glxl = "";       //Eta_b 锅炉效率
            string Q2 = "";
            string Q3 = "0.3";
            string Q4 = "";
            string Q5 = "";
            string Q6 = "";

            if (repType == "日报")
            {

                object obj;
                int ret = 0;
                double val = 0;
                string sql = "";
                string pName = "";

                #region

                if (unit == 0)
                {
                    string pywdA = "";
                    string pywdB = "";
                    string sfwdA = "";
                    string sfwdB = "";

                    //排烟温度
                    sql = "select 日点 from T_Sheet_SheetPara where 参数名='排烟温度' and 报表名称='" + repName + "' and 机组=" + "1";
                    obj = DBsql.RunSingle(sql, out errMsg);
                    if (obj != null)
                        pName = obj.ToString();

                    ek.GetHisValue(pName, jsrq, ref ret, ref val);

                    pywdA = val.ToString();

                    //送风机出口温度
                    sql = "select 日点 from T_Sheet_SheetPara where 参数名='送风机出口温度' and 报表名称='" + repName + "' and 机组=" + "2";
                    obj = DBsql.RunSingle(sql, out errMsg);
                    if (obj != null)
                        pName = obj.ToString();

                    ek.GetHisValue(pName, jsrq, ref ret, ref val);

                    sfwdA = val.ToString();

                    //排烟温度
                    sql = "select 日点 from T_Sheet_SheetPara where 参数名='排烟温度' and 报表名称='" + repName + "' and 机组=" + "1";
                    obj = DBsql.RunSingle(sql, out errMsg);
                    if (obj != null)
                        pName = obj.ToString();

                    ek.GetHisValue(pName, jsrq, ref ret, ref val);

                    pywdB = val.ToString();

                    //送风机出口温度
                    sql = "select 日点 from T_Sheet_SheetPara where 参数名='送风机出口温度' and 报表名称='" + repName + "' and 机组=" + "2";
                    obj = DBsql.RunSingle(sql, out errMsg);
                    if (obj != null)
                        pName = obj.ToString();

                    ek.GetHisValue(pName, jsrq, ref ret, ref val);

                    sfwdB = val.ToString();

                    mon = "(((" + pywdA.ToString() + ")*(" + tjxsA + "))+((" + pywdB.ToString() + ")*(" + tjxsB + ")))/((" + tjxsA + ")+(" + tjxsB + "))";

                    try { glPYwd = StrHelper.Cale(mon); }
                    catch { glPYwd = "0"; }

                    glPYwd = StrHelper.checkCatch(glPYwd);

                    mon = "(((" + sfwdA.ToString() + ")*(" + tjxsA + "))+((" + sfwdB.ToString() + ")*(" + tjxsB + ")))/((" + tjxsA + ")+(" + tjxsB + "))";

                    try { glSFwd = StrHelper.Cale(mon); }
                    catch { glSFwd = "0"; }

                    glSFwd = StrHelper.checkCatch(glSFwd);
                }
                else
                {
                    //排烟温度
                    sql = "select 日点 from T_Sheet_SheetPara where 参数名='排烟温度' and 报表名称='" + repName + "' and 机组=" + unit;
                    obj = DBsql.RunSingle(sql, out errMsg);
                    if (obj != null)
                        pName = obj.ToString();

                    ek.GetHisValue(pName, jsrq, ref ret, ref val);

                    glPYwd = val.ToString();

                    //送风机出口温度
                    sql = "select 日点 from T_Sheet_SheetPara where 参数名='送风机出口温度' and 报表名称='" + repName + "' and 机组=" + unit;
                    obj = DBsql.RunSingle(sql, out errMsg);
                    if (obj != null)
                        pName = obj.ToString();

                    ek.GetHisValue(pName, jsrq, ref ret, ref val);

                    glSFwd = val.ToString();
                }
                try
                {
                    string strQ2 = "((0.9657+0.0005*(" + glPYwd + ")-0.000001*(" + glPYwd + ")*(" + glPYwd + "))/(" + Qdw + ")*((0.0576+0.02337*(" + Qdw + ")/1000)+(0.699+0.303*(" + Qdw + ")/1000)*(21/(21-(" + glPYyl + "))))*((" + glPYwd + ")-(" + glSFwd + "))*100)+(188/(" + Qdw + ")*((0.9081-0.0163*(" + Qdw + ")/1000)+0.01*((0.0089*(" + Qdw + ")/1000-0.0139)+(0.699+0.303*(" + Qdw + ")/1000)*(21/(21-(" + glPYyl + ")))))*((" + glPYwd + ")-(" + glSFwd + ")))";

                    Q2 = StrHelper.Cale(strQ2);
                    Q2 = StrHelper.checkCatch(Q2);

                    string strQ4 = "337.27*((100-(" + glQS + "))/(100-(" + glNS + "))*(" + glJHFkg + "))*(10*(" + Clz + ")/(100-(" + Clz + "))+90*(" + Cfh + ")/(100-(" + Cfh + ")))/(" + Qdw + ")";

                    Q4 = StrHelper.Cale(strQ4);
                    Q4 = StrHelper.checkCatch(Q4);

                    string strQ5 = "5.82*111.03/((" + zhq + ")/(" + jy + "))";//锅炉蒸发量累计/运行小时=主蒸汽流量  (锅炉蒸发量累计=主蒸汽流量)

                    //string strQ5 = "5.82*111.03/1991";//锅炉蒸发量累计/运行小时=主蒸汽流量

                    Q5 = StrHelper.Cale(strQ5);
                    Q5 = StrHelper.checkCatch(Q5);
                    string strQ6 = "(10*(800-(" + glSFwd + "))*(" + Clzb + ")/(100-(" + Clzb + "))+90*((" + glPYwd + ")-(" + glSFwd + "))*(" + Cfhb + ")/(100-(" + Cfhb + ")))*((100-(" + glQS + "))/(100-(" + glNS + "))*(" + glJHFkg + "))/100/(" + Qdw + ")";

                    Q6 = StrHelper.Cale(strQ6);
                    Q6 = StrHelper.checkCatch(Q6);

                }
                catch (Exception ce)
                {
                    glxl = "0";
                }

                if (glxl != "0")
                {
                    try
                    { glxl = StrHelper.Cale("100-(" + Q2 + ")-(" + Q3 + ")-(" + Q4 + ")-(" + Q5 + ")-(" + Q6 + ")"); }
                    catch { glxl = "0"; }
                }

                #endregion
            }
            else if (repType == "月报")
            {
                object obj;
                int ret = 0;
                double val = 0;
                string sql = "";
                string value = "";
                string pName = "";

                jsrq = sh.LastDayOfMonth(DateTime.Parse(qsrq)).ToString("yyyy-MM-dd 23:mm:ss");

                #region

                if (unit == 0)
                {
                    string pywdA = "";
                    string sfwdA = "";
                    string pywdB = "";
                    string sfwdB = "";

                    //排烟温度
                    sql = "select 月点 from T_Sheet_SheetPara where 参数名='排烟温度' and 报表名称='" + repName + "' and 机组=" + "1";
                    obj = DBsql.RunSingle(sql, out errMsg);
                    if (obj != null)
                        pName = obj.ToString();

                    ek.GetHisValue(pName, jsrq, ref ret, ref val);

                    pywdA = val.ToString();

                    //送风机出口温度
                    sql = "select 月点 from T_Sheet_SheetPara where 参数名='送风机出口温度' and 报表名称='" + repName + "' and 机组=" + "2";
                    obj = DBsql.RunSingle(sql, out errMsg);
                    if (obj != null)
                        pName = obj.ToString();

                    ek.GetHisValue(pName, jsrq, ref ret, ref val);

                    sfwdA = val.ToString();

                    //排烟温度
                    sql = "select 月点 from T_Sheet_SheetPara where 参数名='排烟温度' and 报表名称='" + repName + "' and 机组=" + "1";
                    obj = DBsql.RunSingle(sql, out errMsg);
                    if (obj != null)
                        pName = obj.ToString();

                    ek.GetHisValue(pName, jsrq, ref ret, ref val);

                    pywdB = val.ToString();

                    //送风机出口温度
                    sql = "select 月点 from T_Sheet_SheetPara where 参数名='送风机出口温度' and 报表名称='" + repName + "' and 机组=" + "2";
                    obj = DBsql.RunSingle(sql, out errMsg);
                    if (obj != null)
                        pName = obj.ToString();

                    ek.GetHisValue(pName, jsrq, ref ret, ref val);

                    sfwdB = val.ToString();

                    mon = "(((" + pywdA.ToString() + ")*(" + tjxsA + "))+((" + pywdB.ToString() + ")*(" + tjxsB + ")))/((" + tjxsA + ")+(" + tjxsB + "))";

                    try { glPYwd = StrHelper.Cale(mon); }
                    catch { glPYwd = "0"; }

                    glPYwd = StrHelper.checkCatch(glPYwd);

                    mon = "(((" + sfwdA.ToString() + ")*(" + tjxsA + "))+((" + sfwdB.ToString() + ")*(" + tjxsB + ")))/((" + tjxsA + ")+(" + tjxsB + "))";

                    try { glSFwd = StrHelper.Cale(mon); }
                    catch { glSFwd = "0"; }

                    glSFwd = StrHelper.checkCatch(glSFwd);
                }
                else
                {
                    //排烟温度
                    sql = "select 月点 from T_Sheet_SheetPara where 参数名='排烟温度' and 报表名称='" + repName + "' and 机组=" + unit;
                    obj = DBsql.RunSingle(sql, out errMsg);
                    if (obj != null)
                        pName = obj.ToString();

                    ek.GetHisValue(pName, jsrq, ref ret, ref val);

                    glPYwd = val.ToString();

                    //送风机出口温度
                    sql = "select 月点 from T_Sheet_SheetPara where 参数名='送风机出口温度' and 报表名称='" + repName + "' and 机组=" + unit;
                    obj = DBsql.RunSingle(sql, out errMsg);
                    if (obj != null)
                        pName = obj.ToString();

                    ek.GetHisValue(pName, jsrq, ref ret, ref val);

                    glSFwd = val.ToString();
                }
                try
                {
                    string strQ2 = "((0.9657+0.0005*(" + glPYwd + ")-0.000001*(" + glPYwd + ")*(" + glPYwd + "))/(" + Qdw + ")*((0.0576+0.02337*(" + Qdw + ")/1000)+(0.699+0.303*(" + Qdw + ")/1000)*(21/(21-(" + glPYyl + "))))*((" + glPYwd + ")-(" + glSFwd + "))*100)+(188/(" + Qdw + ")*((0.9081-0.0163*(" + Qdw + ")/1000)+0.01*((0.0089*(" + Qdw + ")/1000-0.0139)+(0.699+0.303*(" + Qdw + ")/1000)*(21/(21-(" + glPYyl + ")))))*((" + glPYwd + ")-(" + glSFwd + ")))";

                    Q2 = StrHelper.Cale(strQ2);
                    Q2 = StrHelper.checkCatch(Q2);

                    string strQ4 = "337.27*((100-(" + glQS + "))/(100-(" + glNS + "))*(" + glJHFkg + "))*(10*(" + Clz + ")/(100-(" + Clz + "))+90*(" + Cfh + ")/(100-(" + Cfh + ")))/(" + Qdw + ")";

                    Q4 = StrHelper.Cale(strQ4);
                    Q4 = StrHelper.checkCatch(Q4);

                    string strQ5 = "5.82*111.03/((" + zhq + ")/(" + jy + "))";//锅炉蒸发量累计/运行小时=主蒸汽流量  (锅炉蒸发量累计=主蒸汽流量)

                    //string strQ5 = "5.82*111.03/1991";//锅炉蒸发量累计/运行小时=主蒸汽流量

                    Q5 = StrHelper.Cale(strQ5);
                    Q5 = StrHelper.checkCatch(Q5);
                    string strQ6 = "(10*(800-(" + glSFwd + "))*(" + Clzb + ")/(100-(" + Clzb + "))+90*((" + glPYwd + ")-(" + glSFwd + "))*(" + Cfhb + ")/(100-(" + Cfhb + ")))*((100-(" + glQS + "))/(100-(" + glNS + "))*(" + glJHFkg + "))/100/(" + Qdw + ")";

                    Q6 = StrHelper.Cale(strQ6);
                    Q6 = StrHelper.checkCatch(Q6);

                }
                catch (Exception ce)
                {
                    glxl = "0";
                }

                if (glxl != "0")
                {
                    try
                    { glxl = StrHelper.Cale("100-(" + Q2 + ")-(" + Q3 + ")-(" + Q4 + ")-(" + Q5 + ")-(" + Q6 + ")"); }
                    catch { glxl = "0"; }
                }

                #endregion
            }
            else if (repType == "年报")
            {
                object obj;
                int ret = 0;
                double val = 0;
                string sql = "";
                string value = "";
                string pName = "";

                #region

                if (unit == 0)
                {
                    string pywdA = "";
                    string sfwdA = "";
                    string pywdB = "";
                    string sfwdB = "";

                    //排烟温度
                    sql = "select 年点 from T_Sheet_SheetPara where 参数名='排烟温度' and 报表名称='" + repName + "' and 机组=" + "1";
                    obj = DBsql.RunSingle(sql, out errMsg);
                    if (obj != null)
                        pName = obj.ToString();

                    ek.GetHisValue(pName, jsrq, ref ret, ref val);

                    pywdA = val.ToString();

                    //送风机出口温度
                    sql = "select 年点 from T_Sheet_SheetPara where 参数名='送风机出口温度' and 报表名称='" + repName + "' and 机组=" + "2";
                    obj = DBsql.RunSingle(sql, out errMsg);
                    if (obj != null)
                        pName = obj.ToString();

                    ek.GetHisValue(pName, jsrq, ref ret, ref val);

                    sfwdA = val.ToString();

                    //排烟温度
                    sql = "select 年点 from T_Sheet_SheetPara where 参数名='排烟温度' and 报表名称='" + repName + "' and 机组=" + "1";
                    obj = DBsql.RunSingle(sql, out errMsg);
                    if (obj != null)
                        pName = obj.ToString();

                    ek.GetHisValue(pName, jsrq, ref ret, ref val);

                    pywdB = val.ToString();

                    //送风机出口温度
                    sql = "select 年点 from T_Sheet_SheetPara where 参数名='送风机出口温度' and 报表名称='" + repName + "' and 机组=" + "2";
                    obj = DBsql.RunSingle(sql, out errMsg);
                    if (obj != null)
                        pName = obj.ToString();

                    ek.GetHisValue(pName, jsrq, ref ret, ref val);

                    sfwdB = val.ToString();

                    mon = "(((" + pywdA.ToString() + ")*(" + tjxsA + "))+((" + pywdB.ToString() + ")*(" + tjxsB + ")))/((" + tjxsA + ")+(" + tjxsB + "))";

                    try { glPYwd = StrHelper.Cale(mon); }
                    catch { glPYwd = "0"; }

                    glPYwd = StrHelper.checkCatch(glPYwd);

                    mon = "(((" + sfwdA.ToString() + ")*(" + tjxsA + "))+((" + sfwdB.ToString() + ")*(" + tjxsB + ")))/((" + tjxsA + ")+(" + tjxsB + "))";

                    try { glSFwd = StrHelper.Cale(mon); }
                    catch { glSFwd = "0"; }

                    glSFwd = StrHelper.checkCatch(glSFwd);
                }
                else
                {
                    //排烟温度
                    sql = "select 年点 from T_Sheet_SheetPara where 参数名='排烟温度' and 报表名称='" + repName + "' and 机组=" + unit;
                    obj = DBsql.RunSingle(sql, out errMsg);
                    if (obj != null)
                        pName = obj.ToString();

                    ek.GetHisValue(pName, jsrq, ref ret, ref val);

                    glPYwd = val.ToString();

                    //送风机出口温度
                    sql = "select 年点 from T_Sheet_SheetPara where 参数名='送风机出口温度' and 报表名称='" + repName + "' and 机组=" + unit;
                    obj = DBsql.RunSingle(sql, out errMsg);
                    if (obj != null)
                        pName = obj.ToString();

                    ek.GetHisValue(pName, jsrq, ref ret, ref val);

                    glSFwd = val.ToString();
                }
                try
                {
                    string strQ2 = "((0.9657+0.0005*(" + glPYwd + ")-0.000001*(" + glPYwd + ")*(" + glPYwd + "))/(" + Qdw + ")*((0.0576+0.02337*(" + Qdw + ")/1000)+(0.699+0.303*(" + Qdw + ")/1000)*(21/(21-(" + glPYyl + "))))*((" + glPYwd + ")-(" + glSFwd + "))*100)+(188/(" + Qdw + ")*((0.9081-0.0163*(" + Qdw + ")/1000)+0.01*((0.0089*(" + Qdw + ")/1000-0.0139)+(0.699+0.303*(" + Qdw + ")/1000)*(21/(21-(" + glPYyl + ")))))*((" + glPYwd + ")-(" + glSFwd + ")))";

                    Q2 = StrHelper.Cale(strQ2);
                    Q2 = StrHelper.checkCatch(Q2);

                    string strQ4 = "337.27*((100-(" + glQS + "))/(100-(" + glNS + "))*(" + glJHFkg + "))*(10*(" + Clz + ")/(100-(" + Clz + "))+90*(" + Cfh + ")/(100-(" + Cfh + ")))/(" + Qdw + ")";

                    Q4 = StrHelper.Cale(strQ4);
                    Q4 = StrHelper.checkCatch(Q4);

                    string strQ5 = "5.82*111.03/((" + zhq + ")/(" + jy + "))";//锅炉蒸发量累计/运行小时=主蒸汽流量  (锅炉蒸发量累计=主蒸汽流量)

                    //string strQ5 = "5.82*111.03/1991";//锅炉蒸发量累计/运行小时=主蒸汽流量

                    Q5 = StrHelper.Cale(strQ5);
                    Q5 = StrHelper.checkCatch(Q5);
                    string strQ6 = "(10*(800-(" + glSFwd + "))*(" + Clzb + ")/(100-(" + Clzb + "))+90*((" + glPYwd + ")-(" + glSFwd + "))*(" + Cfhb + ")/(100-(" + Cfhb + ")))*((100-(" + glQS + "))/(100-(" + glNS + "))*(" + glJHFkg + "))/100/(" + Qdw + ")";

                    Q6 = StrHelper.Cale(strQ6);
                    Q6 = StrHelper.checkCatch(Q6);

                }
                catch (Exception ce)
                {
                    glxl = "0";
                }

                if (glxl != "0")
                {
                    try
                    { glxl = StrHelper.Cale("100-(" + Q2 + ")-(" + Q3 + ")-(" + Q4 + ")-(" + Q5 + ")-(" + Q6 + ")"); }
                    catch { glxl = "0"; }
                }

                #endregion
            }

            return "Q2+" + Q2 + ";Q4+" + Q4 + ";Q5+" + Q5 + ";Q6+" + Q6 + ";glxl+" + glxl;
        }

        //综合
        /// <summary>
        /// 煤质分析数据
        /// </summary>
        /// <param name="repName"></param>
        /// <param name="repType"></param>
        /// <param name="qsrq"></param>
        /// <returns></returns>
        public string mzfx(string repName, string repType, string qsrq, int unit)
        {
            string hf1krw1 = "";    //挥发可燃物1
            string hf1krw2 = "";
            string hf1krw3 = "";
            string hf2krw1 = "";    //挥发可燃物2
            string hf2krw2 = "";
            string hf2krw3 = "";

            string mz1ml1 = "0";     //煤量1
            string mz1ml2 = "0";
            string mz1ml3 = "0";

            string mz2ml1 = "0";     //煤量2
            string mz2ml2 = "0";
            string mz2ml3 = "0";

            string mzhf1 = "0";     //灰份
            string mzhf2 = "0";
            string mzhf3 = "0";

            string mzhff1 = "0";    //挥发份
            string mzhff2 = "0";
            string mzhff3 = "0";

            string ns1 = "0";
            string ns2 = "0";
            string ns3 = "0";

            string qs1 = "0";
            string qs2 = "0";
            string qs3 = "0";

            string dwfrl1 = "0";
            string dwfrl2 = "0";
            string dwfrl3 = "0";

            string ns = "0";
            string qs = "0";
            string ml = "0";
            string hf = "0";
            string hff = "0";
            string hfkrw = "0";

            #region 煤质分析数据

            if (repType == "日报")
            {
                string sql = "select * from 入炉煤质分析表 where 日期='" + qsrq + "'";

                DataTable dtmt = DBsql.RunDataTable(sql, out errMsg);

                #region
                if (dtmt.Rows.Count > 0)
                {
                    if (dtmt.Rows.Count == 1)
                    {
                        mzhf1 = dtmt.Rows[0]["灰份"].ToString();
                        mzhff1 = dtmt.Rows[0]["挥发份"].ToString();

                        mz1ml1 = dtmt.Rows[0]["煤量1"].ToString();
                        mz2ml1 = dtmt.Rows[0]["煤量2"].ToString();

                        hf1krw1 = dtmt.Rows[0]["飞灰可燃物1"].ToString();
                        hf2krw1 = dtmt.Rows[0]["飞灰可燃物2"].ToString();

                        ns1 = dtmt.Rows[0]["内在水份"].ToString();
                        qs1 = dtmt.Rows[0]["全水份"].ToString();

                        dwfrl1 = dtmt.Rows[0]["低位发热量"].ToString();
                    }
                    else if (dtmt.Rows.Count == 2)
                    {
                        mzhf1 = dtmt.Rows[0]["灰份"].ToString();
                        mzhf2 = dtmt.Rows[1]["灰份"].ToString();

                        mzhff1 = dtmt.Rows[0]["挥发份"].ToString();
                        mzhff2 = dtmt.Rows[1]["挥发份"].ToString();

                        hf1krw1 = dtmt.Rows[0]["飞灰可燃物1"].ToString();
                        hf1krw2 = dtmt.Rows[1]["飞灰可燃物1"].ToString();
                        hf2krw1 = dtmt.Rows[0]["飞灰可燃物2"].ToString();
                        hf2krw2 = dtmt.Rows[1]["飞灰可燃物2"].ToString();

                        mz1ml1 = dtmt.Rows[0]["煤量1"].ToString();
                        mz1ml2 = dtmt.Rows[1]["煤量1"].ToString();
                        mz2ml1 = dtmt.Rows[0]["煤量2"].ToString();
                        mz2ml2 = dtmt.Rows[1]["煤量2"].ToString();

                        ns1 = dtmt.Rows[0]["内在水份"].ToString();
                        qs1 = dtmt.Rows[0]["全水份"].ToString();
                        ns2 = dtmt.Rows[1]["内在水份"].ToString();
                        qs2 = dtmt.Rows[1]["全水份"].ToString();

                        dwfrl1 = dtmt.Rows[0]["低位发热量"].ToString();
                        dwfrl2 = dtmt.Rows[1]["低位发热量"].ToString();
                    }
                    else if (dtmt.Rows.Count == 3)
                    {
                        mzhf1 = dtmt.Rows[0]["灰份"].ToString();
                        mzhf2 = dtmt.Rows[1]["灰份"].ToString();
                        mzhf3 = dtmt.Rows[2]["灰份"].ToString();

                        mzhff1 = dtmt.Rows[0]["挥发份"].ToString();
                        mzhff2 = dtmt.Rows[1]["挥发份"].ToString();
                        mzhff3 = dtmt.Rows[2]["挥发份"].ToString();

                        hf1krw1 = dtmt.Rows[0]["飞灰可燃物1"].ToString();
                        hf1krw2 = dtmt.Rows[1]["飞灰可燃物1"].ToString();
                        hf1krw3 = dtmt.Rows[2]["飞灰可燃物1"].ToString();
                        hf2krw1 = dtmt.Rows[0]["飞灰可燃物2"].ToString();
                        hf2krw2 = dtmt.Rows[1]["飞灰可燃物2"].ToString();
                        hf2krw3 = dtmt.Rows[2]["飞灰可燃物2"].ToString();

                        mz1ml1 = dtmt.Rows[0]["煤量1"].ToString();
                        mz1ml2 = dtmt.Rows[1]["煤量1"].ToString();
                        mz1ml3 = dtmt.Rows[2]["煤量1"].ToString();
                        mz2ml1 = dtmt.Rows[0]["煤量2"].ToString();
                        mz2ml2 = dtmt.Rows[1]["煤量2"].ToString();
                        mz2ml3 = dtmt.Rows[2]["煤量2"].ToString();

                        ns1 = dtmt.Rows[0]["内在水份"].ToString();
                        qs1 = dtmt.Rows[0]["全水份"].ToString();
                        ns2 = dtmt.Rows[1]["内在水份"].ToString();
                        qs2 = dtmt.Rows[1]["全水份"].ToString();
                        ns3 = dtmt.Rows[2]["内在水份"].ToString();
                        qs3 = dtmt.Rows[2]["全水份"].ToString();

                        dwfrl1 = dtmt.Rows[0]["低位发热量"].ToString();
                        dwfrl2 = dtmt.Rows[1]["低位发热量"].ToString();
                        dwfrl3 = dtmt.Rows[2]["低位发热量"].ToString();
                    }

                }
                #endregion

                if (unit == 0)
                {
                    #region 煤量 OK
                    try
                    {
                        ml = "0";
                        mon = "((" + mz1ml1 + ")+(" + mz1ml2 + ")+(" + mz1ml3 + ")+(" + mz2ml1 + ")+(" + mz2ml2 + ")+(" + mz2ml3 + "))";
                        ml = StrHelper.Cale(mon);
                        ml = StrHelper.checkCatch(ml);
                    }
                    catch
                    {
                        mon = "";
                        ml = "0";
                    }

                    #endregion

                    #region 灰份 OK
                    try
                    {
                        mon = "((" + mzhf1 + "*((" + mz1ml1 + ")+(" + mz2ml1 + ")))+(" + mzhf2 + "*((" + mz1ml2 + ")+(" + mz2ml2 + ")))+(" + mzhf3 + "*((" + mz1ml3 + ")+(" + mz2ml3 + "))))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + ")+(" + mz2ml1 + ") + (" + mz2ml2 + ") + (" + mz2ml3 + "))";
                        hf = StrHelper.Cale(mon);
                        hf = StrHelper.checkCatch(hf);
                    }
                    catch
                    {
                        mon = "";
                        hf = "0";
                    }
                    #endregion

                    #region 挥发份 OK

                    try
                    {
                        mon = "((" + mzhff1 + "*((" + mz1ml1 + ")+(" + mz2ml1 + ")))+(" + mzhff2 + "*((" + mz1ml2 + ")+(" + mz2ml2 + ")))+(" + mzhff3 + "*((" + mz1ml3 + ")+(" + mz2ml3 + "))))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + ")+(" + mz2ml1 + ") + (" + mz2ml2 + ") + (" + mz2ml3 + "))";
                        hff = StrHelper.Cale(mon);
                        hff = StrHelper.checkCatch(hff);
                    }
                    catch
                    { hff = ""; }

                    #endregion

                    #region 挥发可燃物 OK
                    try
                    {
                        mon = "((" + hf1krw1 + "*((" + mz1ml1 + ")+(" + mz2ml1 + ")))+(" + hf1krw2 + "*((" + mz1ml2 + ")+(" + mz2ml2 + ")))+(" + hf1krw3 + "*((" + mz1ml3 + ")+(" + mz2ml3 + "))))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + ")+(" + mz2ml1 + ") + (" + mz2ml2 + ") + (" + mz2ml3 + "))";
                        hfkrw = StrHelper.Cale(mon);
                        hfkrw = StrHelper.checkCatch(hfkrw);
                    }
                    catch
                    { hfkrw = "0"; }

                    #endregion

                    #region 内水 OK
                    try
                    {
                        mon = "((" + ns1 + "*((" + mz1ml1 + ")+(" + mz2ml1 + ")))+(" + ns2 + "*((" + mz1ml2 + ")+(" + mz2ml2 + ")))+(" + ns3 + "*((" + mz1ml3 + ")+(" + mz2ml3 + "))))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + ")+(" + mz2ml1 + ") + (" + mz2ml2 + ") + (" + mz2ml3 + "))";
                        ns = StrHelper.Cale(mon);
                        ns = StrHelper.checkCatch(ns);
                    }
                    catch
                    { ns = "0"; }
                    #endregion

                    #region 全水 OK
                    try
                    {
                        mon = "((" + qs1 + "*((" + mz1ml1 + ")+(" + mz2ml1 + ")))+(" + qs2 + "*((" + mz1ml2 + ")+(" + mz2ml2 + ")))+(" + qs3 + "*((" + mz1ml3 + ")+(" + mz2ml3 + "))))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + ")+(" + mz2ml1 + ") + (" + mz2ml2 + ") + (" + mz2ml3 + "))";
                        qs = StrHelper.Cale(mon);
                        qs = StrHelper.checkCatch(qs);
                    }
                    catch
                    { qs = "0"; }
                    #endregion
                }
                else if (unit == 1)
                {
                    #region 煤量 OK
                    try
                    {
                        ml = "0";
                        mon = "((" + mz1ml1 + ")+(" + mz1ml2 + ")+(" + mz1ml3 + "))";
                        ml = StrHelper.Cale(mon);
                        ml = StrHelper.checkCatch(ml);
                    }
                    catch
                    {
                        mon = "";
                        ml = "0";
                    }

                    #endregion

                    #region 灰份 OK
                    try
                    {
                        mon = "((" + mzhf1 + "*" + mz1ml1 + ")+(" + mzhf2 + "*" + mz1ml2 + ")+(" + mzhf3 + "*" + mz1ml3 + "))/((" + mz1ml1 + ")+(" + mz1ml2 + ")+(" + mz1ml3 + "))";
                        hf = StrHelper.Cale(mon);
                        hf = StrHelper.checkCatch(hf);
                    }
                    catch
                    {
                        mon = "";
                        hf = "0";
                    }
                    #endregion

                    #region 挥发份 OK

                    try
                    {
                        mon = "((" + mzhff1 + "*" + mz1ml1 + ")+(" + mzhff2 + "*" + mz1ml2 + ")+( " + mzhff3 + "*" + mz1ml3 + "))/((" + mz1ml1 + ")+(" + mz1ml2 + ")+(" + mz1ml3 + "))";
                        hff = StrHelper.Cale(mon);
                        hff = StrHelper.checkCatch(hff);
                    }
                    catch
                    { hff = ""; }

                    #endregion

                    #region 挥发可燃物 OK
                    try
                    {
                        mon = "((" + hf1krw1 + "*" + mz1ml1 + ")+(" + hf1krw2 + "*" + mz1ml2 + ")+(" + hf1krw3 + "*" + mz1ml3 + "))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + "))";
                        hfkrw = StrHelper.Cale(mon);
                        hfkrw = StrHelper.checkCatch(hfkrw);
                    }
                    catch
                    { hfkrw = "0"; }

                    #endregion

                    #region 内水 OK
                    try
                    {
                        mon = "((" + ns1 + "*" + mz1ml1 + ")+(" + ns2 + "*" + mz1ml2 + ")+(" + ns3 + "*" + mz1ml3 + "))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + "))";
                        ns = StrHelper.Cale(mon);
                        ns = StrHelper.checkCatch(ns);
                    }
                    catch
                    { ns = "0"; }
                    #endregion

                    #region 全水 OK
                    try
                    {
                        mon = "((" + qs1 + "*" + mz1ml1 + ")+(" + qs2 + "*" + mz1ml2 + ")+(" + qs3 + "*" + mz1ml3 + "))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + "))";
                        qs = StrHelper.Cale(mon);
                        qs = StrHelper.checkCatch(qs);
                    }
                    catch
                    { qs = "0"; }
                    #endregion
                }
                else
                {
                    #region 煤量 OK

                    try
                    {
                        ml = "0";
                        mon = "((" + mz2ml1 + ")+(" + mz2ml2 + ")+(" + mz2ml3 + "))";
                        ml = StrHelper.Cale(mon);
                        ml = StrHelper.checkCatch(ml);
                    }
                    catch
                    {
                        mon = "";
                        ml = "0";
                    }

                    #endregion

                    #region 灰份 OK
                    try
                    {
                        mon = "((" + mzhf1 + "*" + mz2ml1 + ")+(" + mzhf2 + "*" + mz2ml2 + ")+(" + mzhf3 + "*" + mz2ml3 + "))/((" + mz2ml1 + ")+(" + mz2ml2 + ")+(" + mz2ml3 + "))";
                        hf = StrHelper.Cale(mon);
                        hf = StrHelper.checkCatch(hf);
                    }
                    catch
                    {
                        mon = "";
                        hf = "0";
                    }
                    #endregion

                    #region 挥发份 OK
                    try
                    {
                        mon = "((" + mzhff1 + "*" + mz2ml1 + ")+(" + mzhff2 + "*" + mz2ml2 + ")+( " + mzhff3 + "*" + mz2ml3 + "))/((" + mz2ml1 + ")+(" + mz2ml2 + ")+(" + mz2ml3 + "))";
                        hff = StrHelper.Cale(mon);
                        hff = StrHelper.checkCatch(hff);
                    }
                    catch
                    { hff = ""; }

                    #endregion

                    #region 挥发可燃物 OK
                    try
                    {
                        mon = "((" + hf2krw1 + "*" + mz2ml1 + ")+(" + hf2krw2 + "*" + mz2ml2 + ")+(" + hf2krw3 + "*" + mz2ml3 + "))/((" + mz2ml1 + ") + (" + mz2ml2 + ") + (" + mz2ml3 + "))";
                        hfkrw = StrHelper.Cale(mon);
                        hfkrw = StrHelper.checkCatch(hfkrw);
                    }
                    catch
                    { hfkrw = "0"; }
                    #endregion

                    #region 内水 OK
                    try
                    {
                        mon = "((" + ns1 + "*" + mz1ml1 + ")+(" + ns2 + "*" + mz1ml2 + ")+(" + ns3 + "*" + mz1ml3 + "))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + "))";
                        ns = StrHelper.Cale(mon);
                        ns = StrHelper.checkCatch(ns);
                    }
                    catch
                    { ns = "0"; }
                    #endregion

                    #region 全水 OK
                    try
                    {
                        mon = "((" + qs1 + "*" + mz1ml1 + ")+(" + qs2 + "*" + mz1ml2 + ")+(" + qs3 + "*" + mz1ml3 + "))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + "))";
                        qs = StrHelper.Cale(mon);
                        qs = StrHelper.checkCatch(qs);
                    }
                    catch
                    { qs = "0"; }
                    #endregion
                }

            }
            #endregion

            return "ml+" + ml + ";hf+" + hf + ";hff+" + hff + ";hfkrw+" + hfkrw + ";ns+" + ns + ";qs+" + qs;
        }


        public string mzfx(string repName, string repType, string qsrq, string jsrq, int unit)
        {
            string hf1krw1 = "";    //挥发可燃物1
            string hf1krw2 = "";
            string hf1krw3 = "";
            string hf2krw1 = "";    //挥发可燃物2
            string hf2krw2 = "";
            string hf2krw3 = "";

            string mz1ml1 = "0";     //煤量1
            string mz1ml2 = "0";
            string mz1ml3 = "0";

            string mz2ml1 = "0";     //煤量2
            string mz2ml2 = "0";
            string mz2ml3 = "0";

            string mzhf1 = "0";     //灰份
            string mzhf2 = "0";
            string mzhf3 = "0";

            string mzhff1 = "0";    //挥发份
            string mzhff2 = "0";
            string mzhff3 = "0";

            string ns1 = "0";
            string ns2 = "0";
            string ns3 = "0";

            string qs1 = "0";
            string qs2 = "0";
            string qs3 = "0";

            string dwfrl1 = "0";
            string dwfrl2 = "0";
            string dwfrl3 = "0";

            string ns = "0";
            string qs = "0";
            string ml = "0";
            string hf = "0";
            string hff = "0";
            string hfkrw = "0";

            string[] date;
            string monMl = "";
            string monHf = "";
            string monHff = "";
            string monHfkrw = "";
            string monNs = "";
            string monQs = "";

            #region 煤质分析数据

            if (repType == "月报")
            {
                date = sh.DateDiff(DateTime.Parse(qsrq), DateTime.Parse(jsrq));

                for (int i = 0; i < date.Length - 1; i++)
                {

                    string sql = "select * from 入炉煤质分析表 where 日期='" + date[i] + "'";

                    DataTable dtmt = DBsql.RunDataTable(sql, out errMsg);

                    #region
                    if (dtmt.Rows.Count > 0)
                    {
                        if (dtmt.Rows.Count == 1)
                        {
                            mzhf1 = dtmt.Rows[0]["灰份"].ToString();
                            mzhff1 = dtmt.Rows[0]["挥发份"].ToString();

                            mz1ml1 = dtmt.Rows[0]["煤量1"].ToString();
                            mz2ml1 = dtmt.Rows[0]["煤量2"].ToString();

                            hf1krw1 = dtmt.Rows[0]["飞灰可燃物1"].ToString();
                            hf2krw1 = dtmt.Rows[0]["飞灰可燃物2"].ToString();

                            ns1 = dtmt.Rows[0]["内在水份"].ToString();
                            qs1 = dtmt.Rows[0]["全水份"].ToString();

                            dwfrl1 = dtmt.Rows[0]["低位发热量"].ToString();
                        }
                        else if (dtmt.Rows.Count == 2)
                        {
                            mzhf1 = dtmt.Rows[0]["灰份"].ToString();
                            mzhf2 = dtmt.Rows[1]["灰份"].ToString();

                            mzhff1 = dtmt.Rows[0]["挥发份"].ToString();
                            mzhff2 = dtmt.Rows[1]["挥发份"].ToString();

                            hf1krw1 = dtmt.Rows[0]["飞灰可燃物1"].ToString();
                            hf1krw2 = dtmt.Rows[1]["飞灰可燃物1"].ToString();
                            hf2krw1 = dtmt.Rows[0]["飞灰可燃物2"].ToString();
                            hf2krw2 = dtmt.Rows[1]["飞灰可燃物2"].ToString();

                            mz1ml1 = dtmt.Rows[0]["煤量1"].ToString();
                            mz1ml2 = dtmt.Rows[1]["煤量1"].ToString();
                            mz2ml1 = dtmt.Rows[0]["煤量2"].ToString();
                            mz2ml2 = dtmt.Rows[1]["煤量2"].ToString();

                            ns1 = dtmt.Rows[0]["内在水份"].ToString();
                            qs1 = dtmt.Rows[0]["全水份"].ToString();
                            ns2 = dtmt.Rows[1]["内在水份"].ToString();
                            qs2 = dtmt.Rows[1]["全水份"].ToString();

                            dwfrl1 = dtmt.Rows[0]["低位发热量"].ToString();
                            dwfrl2 = dtmt.Rows[1]["低位发热量"].ToString();
                        }
                        else if (dtmt.Rows.Count == 3)
                        {
                            mzhf1 = dtmt.Rows[0]["灰份"].ToString();
                            mzhf2 = dtmt.Rows[1]["灰份"].ToString();
                            mzhf3 = dtmt.Rows[2]["灰份"].ToString();

                            mzhff1 = dtmt.Rows[0]["挥发份"].ToString();
                            mzhff2 = dtmt.Rows[1]["挥发份"].ToString();
                            mzhff3 = dtmt.Rows[2]["挥发份"].ToString();

                            hf1krw1 = dtmt.Rows[0]["飞灰可燃物1"].ToString();
                            hf1krw2 = dtmt.Rows[1]["飞灰可燃物1"].ToString();
                            hf1krw3 = dtmt.Rows[2]["飞灰可燃物1"].ToString();
                            hf2krw1 = dtmt.Rows[0]["飞灰可燃物2"].ToString();
                            hf2krw2 = dtmt.Rows[1]["飞灰可燃物2"].ToString();
                            hf2krw3 = dtmt.Rows[2]["飞灰可燃物2"].ToString();

                            mz1ml1 = dtmt.Rows[0]["煤量1"].ToString();
                            mz1ml2 = dtmt.Rows[1]["煤量1"].ToString();
                            mz1ml3 = dtmt.Rows[2]["煤量1"].ToString();
                            mz2ml1 = dtmt.Rows[0]["煤量2"].ToString();
                            mz2ml2 = dtmt.Rows[1]["煤量2"].ToString();
                            mz2ml3 = dtmt.Rows[2]["煤量2"].ToString();

                            ns1 = dtmt.Rows[0]["内在水份"].ToString();
                            qs1 = dtmt.Rows[0]["全水份"].ToString();
                            ns2 = dtmt.Rows[1]["内在水份"].ToString();
                            qs2 = dtmt.Rows[1]["全水份"].ToString();
                            ns3 = dtmt.Rows[2]["内在水份"].ToString();
                            qs3 = dtmt.Rows[2]["全水份"].ToString();

                            dwfrl1 = dtmt.Rows[0]["低位发热量"].ToString();
                            dwfrl2 = dtmt.Rows[1]["低位发热量"].ToString();
                            dwfrl3 = dtmt.Rows[2]["低位发热量"].ToString();
                        }

                    }
                    else
                    {
                        mzhf1 = "0";
                        mzhf2 = "0";
                        mzhf3 = "0";

                        mzhff1 = "0";
                        mzhff2 = "0";
                        mzhff3 = "0";

                        hf1krw1 = "0";
                        hf1krw2 = "0";
                        hf1krw3 = "0";
                        hf2krw1 = "0";
                        hf2krw2 = "0";
                        hf2krw3 = "0";

                        mz1ml1 = "0";
                        mz1ml2 = "0";
                        mz1ml3 = "0";
                        mz2ml1 = "0";
                        mz2ml2 = "0";
                        mz2ml3 = "0";

                        ns1 = "0";
                        qs1 = "0";
                        ns2 = "0";
                        qs2 = "0";
                        ns3 = "0";
                        qs3 = "0";

                        dwfrl1 = "0";
                        dwfrl2 = "0";
                        dwfrl3 = "0";
                    }
                    #endregion

                    if (unit == 0)
                    {
                        #region 煤量 OK
                        try
                        {
                            ml = "0";
                            mon = "((" + mz1ml1 + ")+(" + mz1ml2 + ")+(" + mz1ml3 + ")+(" + mz2ml1 + ")+(" + mz2ml2 + ")+(" + mz2ml3 + "))";
                            ml = StrHelper.Cale(mon);
                            ml = StrHelper.checkCatch(ml);
                        }
                        catch
                        {
                            mon = "";
                            ml = "0";
                        }

                        #endregion

                        #region 灰份 OK
                        try
                        {
                            mon = "((" + mzhf1 + "*((" + mz1ml1 + ")+(" + mz2ml1 + ")))+(" + mzhf2 + "*((" + mz1ml2 + ")+(" + mz2ml2 + ")))+(" + mzhf3 + "*((" + mz1ml3 + ")+(" + mz2ml3 + "))))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + ")+(" + mz2ml1 + ") + (" + mz2ml2 + ") + (" + mz2ml3 + "))";
                            hf = StrHelper.Cale(mon);
                            hf = StrHelper.checkCatch(hf);
                        }
                        catch
                        {
                            mon = "";
                            hf = "0";
                        }
                        #endregion

                        #region 挥发份 OK

                        try
                        {
                            mon = "((" + mzhff1 + "*((" + mz1ml1 + ")+(" + mz2ml1 + ")))+(" + mzhff2 + "*((" + mz1ml2 + ")+(" + mz2ml2 + ")))+(" + mzhff3 + "*((" + mz1ml3 + ")+(" + mz2ml3 + "))))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + ")+(" + mz2ml1 + ") + (" + mz2ml2 + ") + (" + mz2ml3 + "))";
                            hff = StrHelper.Cale(mon);
                            hff = StrHelper.checkCatch(hff);
                        }
                        catch
                        { hff = ""; }

                        #endregion

                        #region 挥发可燃物 OK
                        try
                        {
                            mon = "((" + hf1krw1 + "*((" + mz1ml1 + ")+(" + mz2ml1 + ")))+(" + hf1krw2 + "*((" + mz1ml2 + ")+(" + mz2ml2 + ")))+(" + hf1krw3 + "*((" + mz1ml3 + ")+(" + mz2ml3 + "))))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + ")+(" + mz2ml1 + ") + (" + mz2ml2 + ") + (" + mz2ml3 + "))";
                            hfkrw = StrHelper.Cale(mon);
                            hfkrw = StrHelper.checkCatch(hfkrw);
                        }
                        catch
                        { hfkrw = "0"; }

                        #endregion

                        #region 内水 OK
                        try
                        {
                            mon = "((" + ns1 + "*((" + mz1ml1 + ")+(" + mz2ml1 + ")))+(" + ns2 + "*((" + mz1ml2 + ")+(" + mz2ml2 + ")))+(" + ns3 + "*((" + mz1ml3 + ")+(" + mz2ml3 + "))))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + ")+(" + mz2ml1 + ") + (" + mz2ml2 + ") + (" + mz2ml3 + "))";
                            ns = StrHelper.Cale(mon);
                            ns = StrHelper.checkCatch(ns);
                        }
                        catch
                        { ns = "0"; }
                        #endregion

                        #region 全水 OK
                        try
                        {
                            mon = "((" + qs1 + "*((" + mz1ml1 + ")+(" + mz2ml1 + ")))+(" + qs2 + "*((" + mz1ml2 + ")+(" + mz2ml2 + ")))+(" + qs3 + "*((" + mz1ml3 + ")+(" + mz2ml3 + "))))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + ")+(" + mz2ml1 + ") + (" + mz2ml2 + ") + (" + mz2ml3 + "))";
                            qs = StrHelper.Cale(mon);
                            qs = StrHelper.checkCatch(qs);
                        }
                        catch
                        { qs = "0"; }
                        #endregion
                    }
                    else if (unit == 1)
                    {
                        #region 煤量 OK
                        try
                        {
                            ml = "0";
                            mon = "((" + mz1ml1 + ")+(" + mz1ml2 + ")+(" + mz1ml3 + "))";
                            ml = StrHelper.Cale(mon);
                            ml = StrHelper.checkCatch(ml);
                        }
                        catch
                        {
                            mon = "";
                            ml = "0";
                        }

                        #endregion

                        #region 灰份 OK
                        try
                        {
                            mon = "((" + mzhf1 + "*" + mz1ml1 + ")+(" + mzhf2 + "*" + mz1ml2 + ")+(" + mzhf3 + "*" + mz1ml3 + "))/((" + mz1ml1 + ")+(" + mz1ml2 + ")+(" + mz1ml3 + "))";
                            hf = StrHelper.Cale(mon);
                            hf = StrHelper.checkCatch(hf);
                        }
                        catch
                        {
                            mon = "";
                            hf = "0";
                        }
                        #endregion

                        #region 挥发份 OK

                        try
                        {
                            mon = "((" + mzhff1 + "*" + mz1ml1 + ")+(" + mzhff2 + "*" + mz1ml2 + ")+( " + mzhff3 + "*" + mz1ml3 + "))/((" + mz1ml1 + ")+(" + mz1ml2 + ")+(" + mz1ml3 + "))";
                            hff = StrHelper.Cale(mon);
                            hff = StrHelper.checkCatch(hff);
                        }
                        catch
                        { hff = ""; }

                        #endregion

                        #region 挥发可燃物 OK
                        try
                        {
                            mon = "((" + hf1krw1 + "*" + mz1ml1 + ")+(" + hf1krw2 + "*" + mz1ml2 + ")+(" + hf1krw3 + "*" + mz1ml3 + "))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + "))";
                            hfkrw = StrHelper.Cale(mon);
                            hfkrw = StrHelper.checkCatch(hfkrw);
                        }
                        catch
                        { hfkrw = "0"; }

                        #endregion

                        #region 内水 OK
                        try
                        {
                            mon = "((" + ns1 + "*" + mz1ml1 + ")+(" + ns2 + "*" + mz1ml2 + ")+(" + ns3 + "*" + mz1ml3 + "))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + "))";
                            ns = StrHelper.Cale(mon);
                            ns = StrHelper.checkCatch(ns);
                        }
                        catch
                        { ns = "0"; }
                        #endregion

                        #region 全水 OK
                        try
                        {
                            mon = "((" + qs1 + "*" + mz1ml1 + ")+(" + qs2 + "*" + mz1ml2 + ")+(" + qs3 + "*" + mz1ml3 + "))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + "))";
                            qs = StrHelper.Cale(mon);
                            qs = StrHelper.checkCatch(qs);
                        }
                        catch
                        { qs = "0"; }
                        #endregion
                    }
                    else
                    {
                        #region 煤量 OK

                        try
                        {
                            ml = "0";
                            mon = "((" + mz2ml1 + ")+(" + mz2ml2 + ")+(" + mz2ml3 + "))";
                            ml = StrHelper.Cale(mon);
                            ml = StrHelper.checkCatch(ml);
                        }
                        catch
                        {
                            mon = "";
                            ml = "0";
                        }

                        #endregion

                        #region 灰份 OK
                        try
                        {
                            mon = "((" + mzhf1 + "*" + mz2ml1 + ")+(" + mzhf2 + "*" + mz2ml2 + ")+(" + mzhf3 + "*" + mz2ml3 + "))/((" + mz2ml1 + ")+(" + mz2ml2 + ")+(" + mz2ml3 + "))";
                            hf = StrHelper.Cale(mon);
                            hf = StrHelper.checkCatch(hf);
                        }
                        catch
                        {
                            mon = "";
                            hf = "0";
                        }
                        #endregion

                        #region 挥发份 OK
                        try
                        {
                            mon = "((" + mzhff1 + "*" + mz2ml1 + ")+(" + mzhff2 + "*" + mz2ml2 + ")+( " + mzhff3 + "*" + mz2ml3 + "))/((" + mz2ml1 + ")+(" + mz2ml2 + ")+(" + mz2ml3 + "))";
                            hff = StrHelper.Cale(mon);
                            hff = StrHelper.checkCatch(hff);
                        }
                        catch
                        { hff = ""; }

                        #endregion

                        #region 挥发可燃物 OK
                        try
                        {
                            mon = "((" + hf2krw1 + "*" + mz2ml1 + ")+(" + hf2krw2 + "*" + mz2ml2 + ")+(" + hf2krw3 + "*" + mz2ml3 + "))/((" + mz2ml1 + ") + (" + mz2ml2 + ") + (" + mz2ml3 + "))";
                            hfkrw = StrHelper.Cale(mon);
                            hfkrw = StrHelper.checkCatch(hfkrw);
                        }
                        catch
                        { hfkrw = "0"; }
                        #endregion

                        #region 内水 OK
                        try
                        {
                            mon = "((" + ns1 + "*" + mz1ml1 + ")+(" + ns2 + "*" + mz1ml2 + ")+(" + ns3 + "*" + mz1ml3 + "))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + "))";
                            ns = StrHelper.Cale(mon);
                            ns = StrHelper.checkCatch(ns);
                        }
                        catch
                        { ns = "0"; }
                        #endregion

                        #region 全水 OK
                        try
                        {
                            mon = "((" + qs1 + "*" + mz1ml1 + ")+(" + qs2 + "*" + mz1ml2 + ")+(" + qs3 + "*" + mz1ml3 + "))/((" + mz1ml1 + ") + (" + mz1ml2 + ") + (" + mz1ml3 + "))";
                            qs = StrHelper.Cale(mon);
                            qs = StrHelper.checkCatch(qs);
                        }
                        catch
                        { qs = "0"; }
                        #endregion
                    }

                    monMl = "(" + ml + ")+";
                    monHf = "(" + hf + ")+";
                    monHff = "(" + hff + ")+";
                    monHfkrw = "(" + hfkrw + ")+";
                    monNs = "(" + ns + ")+";
                    monQs = "(" + qs + ")+";
                }
            }
            #endregion

            try
            {
                ml = StrHelper.Cale(monMl.TrimEnd('+'));
                hf = StrHelper.Cale(monHf.TrimEnd('+'));
                hff = StrHelper.Cale(monHff.TrimEnd('+'));
                hfkrw = StrHelper.Cale(monHfkrw.TrimEnd('+'));
                ns = StrHelper.Cale(monNs.TrimEnd('+'));
                qs = StrHelper.Cale(monQs.TrimEnd('+'));
            }
            catch
            {
                ml = "0";
                hf = "0";
                hff = "0";
                hfkrw = "0";
                ns = "0";
                qs = "0";
            }
            ml = StrHelper.checkCatch(ml);
            hf = StrHelper.checkCatch(hf);
            hff = StrHelper.checkCatch(hff);
            hfkrw = StrHelper.checkCatch(hfkrw);
            ns = StrHelper.checkCatch(ns);
            qs = StrHelper.checkCatch(qs);

            return "ml+" + ml + ";hf+" + hf + ";hff+" + hff + ";hfkrw+" + hfkrw + ";ns+" + ns + ";qs+" + qs;
        }

        /// <summary>
        /// 购网电量
        /// </summary>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public string gwdl(string qsrq, string jsrq, int unit)
        {
            object obj1;
            object obj2;

            string sql1;
            string sql2;
            string mon = "";
            string res = "";

            double drv = 0;
            double gwdl = 0;

            sql1 = " SELECT SUM(1-运行小时) AS Expr1 FROM 机组运行小时数据表 WHERE (设备类型='发电机') AND (机组 = 1) AND (日期 >= '" + qsrq + "') AND (日期 < '" + jsrq + "')";

            obj1 = DBsql.RunSingle(sql1, out errMsg);

            sql2 = " SELECT SUM(1-运行小时) AS Expr1 FROM 机组运行小时数据表 WHERE (设备类型='发电机') AND (机组 = 2) AND (日期 >= '" + qsrq + "') AND (日期 < '" + jsrq + "')";

            obj2 = DBsql.RunSingle(sql2, out errMsg);

            string fm = obj1.ToString() + "+" + obj2.ToString();

            try
            {
                res = StrHelper.Cale(fm);
            }
            catch (Exception ce)
            { errMsg = ce.Message; }

            drv = double.Parse(pc.GetPower(drv, "qbb1zxyg", qsrq, jsrq, bm).ToString()) / 10000;

            if (obj1.ToString() == "0" && obj2.ToString() == "0")
            {
                if (unit == 1 || unit == 2)
                    gwdl = drv / 2;
                else
                    gwdl = drv;
            }
            else if (obj1.ToString() != "0" || obj2.ToString() != "0")
            {
                if (unit == 1)
                    mon = obj1.ToString() + "/" + res + "*" + drv.ToString();
                else if (unit == 2)
                    mon = obj2.ToString() + "/" + res + "*" + drv.ToString();
                else
                    mon = drv.ToString();

                try
                {
                    res = StrHelper.Cale(mon);
                    gwdl = double.Parse(res);
                }
                catch { gwdl = 0; }
            }
            else
            {
                gwdl = 0;
            }

            //if (errMsg == "" && obj1.ToString() != "0" && obj2.ToString() != "0")
            //{
            //    if (unit == 1)
            //        mon = obj1.ToString() + "/" + res + "*" + drv.ToString();
            //    else if (unit == 2)
            //        mon = obj2.ToString() + "/" + res + "*" + drv.ToString();
            //    else
            //        mon = drv.ToString();

            //    try
            //    {
            //        res = StrHelper.Cale(mon);
            //        gwdl = double.Parse(res);
            //    }
            //    catch { gwdl = 0; }

            //}
            //else
            //{
            //    if (unit == 1 || unit == 2)
            //        gwdl = drv / 2;
            //    else
            //        gwdl = drv;
            //}

            return gwdl.ToString();
        }

        /// <summary>
        /// 购网电量(明细)
        /// </summary>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public string gwdl(string qsrq, string jsrq, int unit, string type)
        {
            object obj1;
            object obj2;

            string sql1;
            string sql2;
            string mon1 = "";
            string mon = "";
            string res = "";

            double drv = 0;
            double gwdl = 0;

            if (type == "mx" || type == "明细")
            {
                string[] date = sh.DateDiff(DateTime.Parse(qsrq), DateTime.Parse(jsrq));

                for (int i = 0; i < date.Length - 1; i++)
                {
                    res = "";
                    mon = "";

                    if (date[i] != null)
                    {
                        qsrq = DateTime.Parse(date[i]).ToString("yyyy-MM-dd 0:00:00");
                        jsrq = DateTime.Parse(date[i]).ToString("yyyy-MM-dd 23:59:59");

                        sql1 = " SELECT SUM(1-运行小时) AS Expr1 FROM 机组运行小时数据表 WHERE (设备类型='发电机') AND (机组 = 1) AND (日期 >= '" + qsrq + "') AND (日期 < '" + jsrq + "')";

                        obj1 = DBsql.RunSingle(sql1, out errMsg);

                        sql2 = " SELECT SUM(1-运行小时) AS Expr1 FROM 机组运行小时数据表 WHERE (设备类型='发电机') AND (机组 = 2) AND (日期 >= '" + qsrq + "') AND (日期 < '" + jsrq + "')";

                        obj2 = DBsql.RunSingle(sql2, out errMsg);

                        string fm = obj1.ToString() + "+" + obj2.ToString();

                        try
                        {
                            res = StrHelper.Cale(fm);
                        }
                        catch (Exception ce)
                        { errMsg = ce.Message; }

                        drv = double.Parse(pc.GetPower(drv, "qbb1zxyg", qsrq, DateTime.Parse(jsrq).AddSeconds(+1).ToString("yyyy-MM-dd 0:00:00"), bm).ToString()) / 10000;

                        if (obj1.ToString() == "0" && obj2.ToString() == "0")
                        {
                            if (unit == 1 || unit == 2)
                                gwdl = drv / 2;
                            else
                                gwdl = drv;

                            mon1 += "(" + gwdl.ToString() + ")+";
                        }
                        else if (obj1.ToString() != "0" || obj2.ToString() != "0")
                        {
                            if (unit == 1)
                                mon = obj1.ToString() + "/" + res + "*" + drv.ToString();
                            else if (unit == 2)
                                mon = obj2.ToString() + "/" + res + "*" + drv.ToString();
                            else
                                mon = drv.ToString();

                            try
                            {
                                res = StrHelper.Cale(mon);
                                mon1 += "(" + res + ")+";
                                //gwdl = double.Parse(res);
                            }
                            catch { mon1 += "(0)+"; }
                        }
                        else
                        {
                            mon1 += "(0)+";
                        }
                    }
                }
            }

            try
            {
                res = "";
                gwdl = 0;

                res = StrHelper.Cale(mon1.TrimEnd('+'));

                gwdl = double.Parse(res);
            }
            catch { gwdl = 0; }

            return gwdl.ToString();
        }

        public string K2(string ID, string[] arr, int unit)
        {
            string pID = "";  //参数ID
            string pVal = ""; //参数值

            string[] idVal = null;
            string[] idVal2 = null;

            string val = "0";
            string value = "0";

            if (arr != null)
            {
                if (unit != 0)
                {
                    for (int j = 0; j < arr.Length; j++)
                    {
                        if (arr[j] != null)
                        {
                            if (arr[j].Contains(';'))
                            {
                                int a = unit - 1;

                                idVal = arr[j].Split(';');

                                if (idVal[a].Contains(','))
                                {
                                    idVal2 = idVal[a].Split(',');

                                    pID = idVal2[0].ToString();
                                    pVal = idVal2[1].ToString();

                                    if (pID.Contains("gzwhjhff"))
                                        value = pVal;
                                }
                            }
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < arr.Length; j++)
                    {
                        if (arr[j] != null)
                        {
                            if (arr[j].Contains(';'))
                            {
                                idVal = arr[j].Split(';');

                                for (int k = 0; k < idVal.Length; k++)
                                {
                                    if (idVal[k] != "" && idVal[k].Contains(','))
                                    {
                                        idVal2 = idVal[k].Split(',');

                                        pID = idVal2[0].ToString();
                                        pVal = idVal2[1].ToString();

                                        if (pID.Contains("gzwhjhff"))
                                            value = pVal;
                                    }
                                }
                            }
                        }
                    }
                }

                if (double.Parse(value) > 40)
                    val = "0.2595";
                else if (double.Parse(value) > 30 && double.Parse(value) <= 40)
                    val = "0.257";
                else if (double.Parse(value) > 20 && double.Parse(value) <= 30)
                    val = "0.262";
                else if (double.Parse(value) > 10 && double.Parse(value) <= 20)
                    val = "0.2608";
                else
                    val = "0.2659";
            }

            return val;
        }
    }
}
